Repository navigation
test(storage-sqlite): read POSIX locks from /proc/self/fdinfo in the copy tests - #1059
Conversation
…copy tests Two copy tests in refusal_tests.rs read this process's locks on the database from /proc/locks. The kernel returns /proc/locks one page per read, and each read starts again at an index into the lock list. A lock that another test or process takes or releases between two pages moves the entries after it. So a read can skip an entry or list one twice. CI run 43873705049 for #597 failed the setup check "the runner's connection holds no lock" this way. posix_locks now reads the lock: lines of /proc/self/fdinfo. The kernel writes the locks of one file there in one pass, under the spinlock of that file's lock list. A read of fdinfo opens no descriptor on the database, so it releases no lock. The helper returns a set, because a duplicated descriptor lists its file's locks again. Four other processes took and released locks during each loop of 100 runs. With the old helper the two tests failed 10 and 14 times. With this helper both passed 100 of 100. Without the other processes, both helpers passed 100 of 100.
eliseong
left a comment
There was a problem hiding this comment.
LGTM
I ran the two tests 50 times each on a Linux 5.10 aarch64 host. Four other processes took and released POSIX locks in a loop, and 16 processes kept the CPUs busy.
- On main, 11 of 50 runs failed. Three failures were "the runner's connection holds no lock", at lines 475 and 512. The others were "the copy released the runner's lock" and "the search released the runner's lock".
- On this branch, 0 of 50 runs failed.
The new helper still finds a released lock. I added drop(std::fs::File::open(db)) at the start of pre_migration_copy, and the copy test failed at line 480 with left: {}. The same line at the start of remove_superseded made the link test fail at line 523 with left: {}.
In fs/locks.c, show_fd_locks lists the locks of one file under flc_lock in one pass. It keeps only locks set through that file by this process, so the pid check is not necessary. The kernel merges POSIX locks of one owner on one file, so the set loses no entry.
No other code reads /proc/locks. cargo fmt and clippy with -D warnings on Linux are clean.
What
posix_locksis the helper that the two copy lock tests incrates/storage-sqlite/src/migrations/refusal_tests.rsuse. It now reads thelock:lines of/proc/self/fdinfoinstead of/proc/locks, keeps the POSIX lines that name the database's inode, and returns them as a set. The change is test code only.Why
The kernel returns
/proc/locksone page (about 4 KB) per read, and each read starts again at a position in the lock list. When another test in the binary or another process takes or releases a lock between two reads, the entries after it move. A read can then skip the runner's lock or list it twice, and the tests fail. CI run 43873705049 for #597 failed this way.The kernel writes the locks of one file into its fdinfo in one pass, under the spinlock of that file's lock list. A read of fdinfo opens no descriptor on the database, so it releases no lock. A duplicated descriptor lists its file's locks again, so the helper returns a set. Linux added the fdinfo
lock:lines in 4.1, and the runner of the failed job had Linux 7.0.Closes #1058
Testing done
cargo test -p extenddb-storage-sqlite --libwith the two tests,the_copy_leaves_the_runners_lock_on_the_databaseanda_link_to_the_database_under_a_copys_name_is_not_opened: 2 passed.cargo fmt --all --checkis clean.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.