From c248cdea671e125c5feaa94a02d14c435f0ad8e7 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 4 Jan 2024 17:41:58 -0500 Subject: [PATCH] Revert pull request #443 from fractaledmind/lock-wait-timeout This is the outcome of running: git revert f80c5ff0..0c93d308 --- lib/sqlite3/database.rb | 20 --------------- test/test_integration_pending.rb | 44 -------------------------------- 2 files changed, 64 deletions(-) diff --git a/lib/sqlite3/database.rb b/lib/sqlite3/database.rb index 428c680e..206918f9 100644 --- a/lib/sqlite3/database.rb +++ b/lib/sqlite3/database.rb @@ -131,7 +131,6 @@ def initialize file, options = {}, zvfs = nil @type_translator = make_type_translator @type_translation @readonly = mode & Constants::Open::READONLY != 0 @default_transaction_mode = options[:default_transaction_mode] || :deferred - @timeout_deadline = nil if block_given? begin @@ -699,25 +698,6 @@ def readonly? @readonly end - # Sets a #busy_handler that releases the GVL between retries, - # but only retries up to the indicated number of +milliseconds+. - # This is an alternative to #busy_timeout, which holds the GVL - # while SQLite sleeps and retries. - def busy_handler_timeout=( milliseconds ) - timeout_seconds = milliseconds.fdiv(1000) - - busy_handler do |count| - now = Process.clock_gettime(Process::CLOCK_MONOTONIC) - if count.zero? - @timeout_deadline = now + timeout_seconds - elsif now > @timeout_deadline - next false - else - sleep(0.001) - end - end - end - # A helper class for dealing with custom functions (see #create_function, # #create_aggregate, and #create_aggregate_handler). It encapsulates the # opaque function object that represents the current invocation. It also diff --git a/test/test_integration_pending.rb b/test/test_integration_pending.rb index 8f408c16..3f7685c4 100644 --- a/test/test_integration_pending.rb +++ b/test/test_integration_pending.rb @@ -79,48 +79,4 @@ def test_busy_timeout assert time.real*1000 >= 1000 end - - def test_busy_timeout_blocks_gvl - threads = [1, 2].map do - Thread.new do - begin - db = SQLite3::Database.new("test.db") - db.busy_timeout = 3000 - db.transaction(:immediate) do - db.execute "insert into foo ( b ) values ( ? )", rand(1000).to_s - sleep 1 - db.execute "insert into foo ( b ) values ( ? )", rand(1000).to_s - end - ensure - db.close if db - end - end - end - - assert_raise( SQLite3::BusyException ) do - threads.each(&:join) - end - end - - def test_busy_handler_timeout_releases_gvl - threads = [1, 2].map do - Thread.new do - begin - db = SQLite3::Database.new("test.db") - db.busy_handler_timeout = 3000 - db.transaction(:immediate) do - db.execute "insert into foo ( b ) values ( ? )", rand(1000).to_s - sleep 1 - db.execute "insert into foo ( b ) values ( ? )", rand(1000).to_s - end - ensure - db.close if db - end - end - end - - assert_nothing_raised do - threads.each(&:join) - end - end end