You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Concurrent identical whitelist add or remove fails although the operation is idempotent #3052
DatabaseWhitelist::add and remove (packages/tracker-core/src/whitelist/repository/persisted.rs) are written to be idempotent, but they read is_info_hash_whitelisted and then write, without a transaction. Under concurrency the check-then-act races:
Two concurrent add calls of the same info-hash both read "not whitelisted", both insert, and the loser fails with UNIQUE constraint failed: whitelist.info_hash.
Two concurrent remove calls both read "whitelisted"; the loser deletes zero rows, which the store reports as DeleteFailed.
WhitelistManager::add_torrent_to_whitelist (the REST whitelist endpoint) calls add, so one of two simultaneous identical requests gets an error although the hash is whitelisted. Stored data and the in-memory whitelist stay correct; the harm is a false error.
Reproduction
SQLite, temporary database, #[tokio::test(flavor = "multi_thread", worker_threads = 4)], 200 rounds of two concurrent identical add then two concurrent identical remove: both fail in 200 of 200 rounds (first error InvalidQuery { Database(SqliteError { code: 2067, "UNIQUE constraint failed: whitelist.info_hash" }) }). MySQL and PostgreSQL use the same code shape; to be reproduced.
Chosen fix
Make the store writes idempotent (ON CONFLICT DO NOTHING / ON DUPLICATE KEY UPDATE info_hash = info_hash; a delete that accepts zero rows), drop the read-before-write, and replace the three driver tests that document the failures with no-op tests.
Found as finding F4 of #2902 (EPIC #1347). Spec: docs/issues/open/<n>-whitelist-add-remove-race/ISSUE.md, in the spec PR.
Activity
docs(issues): [torrust#3052] clarify the reproduction test is not the…
docs(issues): [torrust#3052] name the spec-only branch in the frontma…
docs(issues): [torrust#3052] plan maintained concurrent cases for MyS…
docs(issues): [torrust#3052] restore the test-development loop and co…
docs(issues): [torrust#3052] quote the recorded store error whole
docs(issues): [torrust#3052] record the reproduction test line as pri…
docs(issues): [torrust#3052] use a template status value for V1
docs(issues): [torrust#3052] move the last-updated-utc of both spec f…
docs(issues): [torrust#3052] plan the concurrent harness cases red be…
docs(issues): [torrust#3052] move the last-updated-utc after the T3 c…
docs(issues): [torrust#3052] commit the T3 tests per file
docs(pr-reviews): [torrust#3052] record the third review round
docs(pr-reviews): [torrust#3052] cite the commit by subject in the audit
docs(issues): [#3052] spec for the concurrent whitelist add/remove race
Merge #3053: docs(issues): [#3052] spec for the concurrent whitelist …
6 remaining items
docs(issues): [torrust#3052] record the red run on MySQL and PostgreSQL
fix(tracker-core): [torrust#3052] make the whitelist add and remove a…
test(tracker-core): [torrust#3052] replace the whitelist failure test…
docs(issues): [torrust#3052] record the final evidence and mark the s…
docs(issues): [torrust#3052] address the first review of the fix PR
docs(pr-reviews): [torrust#3052] record the first review audit of the…
test(tracker-core): [torrust#3052] adapt the failing-store whitelist …
docs(issues): [torrust#3052] log the rebase onto develop and the adap…
docs(pr-reviews): [torrust#3052] record the CodeRabbit pre-merge find…
Merge torrust#3061: fix(tracker-core): [torrust#3052] make the whitel…
docs(issues): [torrust#3052] address the review of the archive pull r…
docs(pr-reviews): [torrust#3052] record the review audit of the archi…
chore(issues): [#3052] archive the whitelist race spec to docs/issues…
Merge #3071: chore(issues): archive the whitelist race spec to docs/i…