File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -691,16 +691,19 @@ def readonly?
691691 @readonly
692692 end
693693
694+ # Sets a #busy_handler that releases the GVL between retries,
695+ # but only retries up to the indicated number of +milliseconds+.
696+ # This is an alternative to #busy_timeout, which holds the GVL
697+ # while SQLite sleeps and retries.
694698 def busy_handler_timeout = ( milliseconds )
695699 timeout_seconds = milliseconds . fdiv ( 1000 )
696700 retry_interval = 0.001 # 1 millisecond
701+ timeout_deadline = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) + timeout_seconds
697702
698703 busy_handler do |count |
699- @start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) if count == 0
704+ next false if Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) > timeout_deadline
700705
701- next sleep ( retry_interval ) unless ( count % 100 ) == 0
702-
703- ( Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - @start_time ) <= timeout_seconds
706+ sleep ( retry_interval )
704707 end
705708 end
706709
You can’t perform that action at this time.
0 commit comments