Skip to content

test: fix flaky fork-safety test caused by leaked writable connections - #763

Merged
flavorjones merged 1 commit into
mainfrom
card-345-fork-safety-test-flake
Oct 26, 2026
Merged

flavorjones merged 1 commit into
mainfrom
card-345-fork-safety-test-flake

Conversation

@flavorjones

Copy link
Copy Markdown
Member

Motivation

test_close_does_not_discard_readonly_connections failed intermittently on arm-linux-musl 4.0: the forked child emitted the fork-safety warning, and the test asserts that it does not (test/test_discarding.rb:144).

The child warns when any tracked writable connection is still open at fork time (lib/sqlite3/fork_safety.rb:39). Some tests leave writable connections open, and the fork tests call GC.start (test/test_discarding.rb:125) to free them before forking. GC.start frees only unreachable objects, so a leaked connection that is still referenced, even conservatively from the machine stack, stays open.

Details

Replace GC.start in the fork tests with a helper that closes every leaked writable SQLite3::Database before the test opens its own connections.

The fork tests in `test_discarding.rb` failed intermittently when a
writable connection leaked by an earlier test was still reachable at
fork time. `GC.start` cannot free a reachable connection, so the child
emitted the fork-safety warning. Close leaked writable connections
before each fork test opens its own.

ref: https://github.com/sparklemotion/sqlite3-ruby/actions/runs/31534307777/job/93923543997
@flavorjones
flavorjones merged commit e4f3d58 into main Oct 26, 2026
135 checks passed
@flavorjones
flavorjones deleted the card-345-fork-safety-test-flake branch October 26, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant