File tree Expand file tree Collapse file tree 3 files changed +9
-0
lines changed Expand file tree Collapse file tree 3 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ def release_lock
14
14
pg_function = "pg_advisory_unlock#{ shared ? '_shared' : '' } "
15
15
execute_successful? ( pg_function )
16
16
rescue ActiveRecord ::StatementInvalid => e
17
+ # If something goes real bad, pg will close the connection. in that case the lock is no longer held
18
+ return if e . message =~ /PG::ConnectionBad:/
17
19
raise unless e . message =~ / ERROR: +current transaction is aborted,/
18
20
19
21
begin
Original file line number Diff line number Diff line change 56
56
57
57
thread_with_lock . kill
58
58
end
59
+
60
+ it 'handles lost connection gracefully' do
61
+ Tag . with_advisory_lock ( lock_name ) { Tag . connection . disconnect! }
62
+
63
+ assert_nil ( Tag . current_advisory_lock )
64
+ end
59
65
end
60
66
61
67
describe '.with_advisory_lock!' do
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ def env_db
37
37
module MiniTest
38
38
class Spec
39
39
before do
40
+ ActiveRecord ::Base . establish_connection
40
41
ENV [ 'FLOCK_DIR' ] = Dir . mktmpdir
41
42
Tag . delete_all
42
43
TagAudit . delete_all
You can’t perform that action at this time.
0 commit comments