Skip to content

Commit 413b59d

Browse files
committed
Sqlite, fix active? and disconnect! is synchronized
1 parent 0adb5b6 commit 413b59d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,19 @@ def supports_concurrent_connections?
164164
!@memory_database
165165
end
166166

167+
def connected?
168+
!(@raw_connection.nil? || @raw_connection.closed?)
169+
end
170+
167171
def active?
168-
@raw_connection && !@raw_connection.closed?
172+
if connected?
173+
@lock.synchronize do
174+
if @raw_connection&.active?
175+
verified!
176+
true
177+
end
178+
end
179+
end || false
169180
end
170181

171182
def return_value_after_insert?(column) # :nodoc:
@@ -177,10 +188,11 @@ def return_value_after_insert?(column) # :nodoc:
177188
# Disconnects from the database if already connected. Otherwise, this
178189
# method does nothing.
179190
def disconnect!
180-
super
181-
182-
@raw_connection&.close rescue nil
183-
@raw_connection = nil
191+
@lock.synchronize do
192+
super
193+
@raw_connection&.close rescue nil
194+
@raw_connection = nil
195+
end
184196
end
185197

186198
def supports_index_sort_order?

0 commit comments

Comments
 (0)