Repository navigation
test(backup): close three races in the backup wire tests - #985
Conversation
LeeroyHannigan
left a comment
There was a problem hiding this comment.
I merged this branch with main at 3a5c84b, built the merge for PostgreSQL and SQLite, and ran the two backup files in a container as root, with moto on loopback and PostgreSQL 16.
What I ran
- CI's command on the PostgreSQL build: 43 pass, 21 skip and 1 fails. The failure is
test_sync_is_refused_while_purge_holds_the_claim, which relies onchmod 0o500. Root ignores that mode, and main's file fails the same way when it runs as root. - On the SQLite build: 49 pass and 16 skip with moto, and 47 pass and 18 skip without an S3 endpoint.
- The counts are lower than the description's because #620 replaced a 4-case cell with a 2-case one, and
test_a_prefix_the_store_cannot_read_leaves_the_sync_incompleteskips as root. - The changed cells passed three more times on each build.
- Moves-sync cell with the release delayed: at 1 s and 5 s, main's cell fails at the landed-row assertion and this branch's passes. This branch's cell also passes at 3 s and 10 s. With
landed_gateremoved and a 1 s delay, it fails at the landed-row assertion. With a 35 s delay it fails after 45 s with "landed_gate: the late row did not land within 30 s". - Port collisions forced on main give CI's errors:
failed validationin the unreachable cell, and "Address already in use" in the store-outage and stalled cells. With the first bind forced onto the server's port,_closed_portand_free_portpick another port and the three cells pass. - Each of these changes fails the cell it targets:
- no
dead.close()before the forwarder starts: the forwarder's bind fails; - a listening socket from
_closed_port: the store stayschecking; - a gate that never opens: the cell fails after 42.8 s with the gate's message;
- the adoptee's prefix left out of the copy: the cell fails at the Adopted assertion.
- no
- Between 11 Nov 01:00 and 12 Nov 20:30 UTC, 14 Integration Tests runs failed: the six the description cites, 2 merge-queue build failures, 3 artifact upload failures and 3 runs of #618's branch.
- This branch merges with main without conflicts. Of the open PRs, it conflicts only with #983, which fixes the tampered and moves-sync cells another way. I'm closing #983 in favour of this PR.
Open items
- Needed before merge: the tampered cell's new log poll repeats
_restore_fails. The inline comment ontests/test_backup_job.py:974has the one-call version. - Minor:
_free_portrepeats_closed_port's loop (tests/test_backup_store_config.py:117). - Minor: the moves-sync cell's new Adopted assertion can use
_adopted_section(tests/test_backup_job.py:3768). - Minor: the stalled cell makes the socket from
_closed_portlisten, and the helper's docstring says that socket is not listening (tests/test_backup_store_config.py:857).
With the three code changes applied, tests/test_backup_store_config.py and the three changed cells of tests/test_backup_job.py passed on both builds.
| # The job logs its FAILED line after it removes the target, so the | ||
| # target can be gone before the line is written: poll for a moment. | ||
| deadline = time.monotonic() + 15 | ||
| while True: | ||
| failed = [line for line in server.log_text().splitlines() if ": FAILED (" in line and f" into {target} " in line] | ||
| if failed or time.monotonic() > deadline: | ||
| break | ||
| time.sleep(0.25) | ||
| assert len(failed) == 1, server.log_text()[-4000:] | ||
| assert "FAILED (data file data/000002.json.gz does not match the manifest" in failed[0], failed[0] |
There was a problem hiding this comment.
Lines 976-985 are the body of _restore_fails (line 1550) with the needle written out. Lines 953-955 are its first three lines. Only the GetItem loop at 956-973 differs: the helper waits with _wait_table_gone, which fails if the target is ever anything but CREATING. The docstring says at 936-938 that a CREATING target answers no read, so the helper still checks that no item became readable. The two other failing-restore cells (lines 1603 and 1627) call it.
Lines 952-985 can be this call:
_restore_fails(
server, ddb, f"{name}-r", arn,
"FAILED (data file data/000002.json.gz does not match the manifest",
)
The docstring's sentence about the GetItem probe (936-938) then goes. With this change the cell passed four times on PostgreSQL and twice on SQLite.
There was a problem hiding this comment.
Done in 398f1be: the cell now calls _restore_fails with that needle, and the GetItem sentence is gone from the docstring. The helper still pins the reason: with the needle changed to the sha256-mismatch text the cell fails.
| while True: | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("127.0.0.1", 0)) | ||
| port = s.getsockname()[1] | ||
| if port not in avoid: | ||
| return port |
There was a problem hiding this comment.
This is _closed_port's loop below, except that the socket is closed. _free_port can call it:
| while True: | |
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
| s.bind(("127.0.0.1", 0)) | |
| port = s.getsockname()[1] | |
| if port not in avoid: | |
| return port | |
| s, port = _closed_port(*avoid) | |
| s.close() | |
| return port |
There was a problem hiding this comment.
Done, _free_port is now _closed_port with the socket closed.
| assert late is not None, result | ||
| assert released, "the move's sync line was printed before it ended" | ||
| assert f"Moved (each row now names the configured store):\n {moved}" in text, text[-4000:] | ||
| assert "--- Adopted (an AVAILABLE row inserted for each):\n " + adoptee in text, text[-4000:] |
There was a problem hiding this comment.
The other sync cells in this file read this section with _adopted_section (line 2351). Comparing the whole list also fails if the sync adopted more than the adoptee:
| assert "--- Adopted (an AVAILABLE row inserted for each):\n " + adoptee in text, text[-4000:] | |
| assert _adopted_section(text).splitlines()[1:-1] == [f" {adoptee}"], text[-4000:] |
There was a problem hiding this comment.
Done, it compares the whole Adopted section with _adopted_section, so an extra adoption fails it too.
| # Never the server's port, which the server has not bound yet. | ||
| tarpit, tarpit_port = _closed_port(d.port) |
There was a problem hiding this comment.
_closed_port's docstring says its socket is not listening, and line 859 makes this one listen. The comment could say so:
| # Never the server's port, which the server has not bound yet. | |
| tarpit, tarpit_port = _closed_port(d.port) | |
| # Never the server's port, which the server has not bound yet. The | |
| # tarpit listens on the socket that `_closed_port` bound. | |
| tarpit, tarpit_port = _closed_port(d.port) |
There was a problem hiding this comment.
Done, the comment now says the tarpit listens on the socket _closed_port bound.
Three backup wire cells failed on main and in the merge queue between 11 and 12 November without a product change. Each depended on timing or on two independently picked ports differing. test_a_tampered_data_file_fails_the_restore_before_any_item read the server log once, as soon as DescribeTable answered ResourceNotFoundException. The restore job removes the target and only then logs its FAILED line, so the read could come first (run 43242599309). The cell now calls _restore_fails, which waits for the target to go (failing if it is ever anything but CREATING), polls the log for the FAILED line for up to 15 s, and checks the reason and the target's removal on it. Its own GetItem probe goes: a CREATING target answers no read. test_a_row_that_lands_during_the_moves_sync_exits_1 relied on the move's sync listing 2,000 junk prefixes for longer than the test took to release the held CreateBackup insert. When the listing won, the late row committed after the command read the other stores' rows and went unreported (runs 42937487371, 43005024164, 43272409754). The cell now drops the row of a second, complete backup before the move, so the sync adopts it, and a second trigger holds that adoption insert until the late row exists. The adoption is the sync's only backup_index write and comes before the closing report's read, so the late row always commits before that read. After 30 s the trigger fails the insert with its own message instead. The junk prefixes are removed, and the cell checks that the report adopted exactly that backup. With the release delayed by 1, 3, 5 or 10 s, the old cell fails at the landed-row assertion and the new one passes. test_an_unreachable_s3_endpoint_starts_the_server_unhealthy_and_recovers picked its dead endpoint port with bind(0) and close, before the server had bound its own port, which was picked the same way. When the two were equal, the server's S3 client reached the server's own TLS listener, which answers plain HTTP with a 301, so the store check reports "failed validation" instead of "unreachable". That is the failure in run 43108980074. The CI log does not show the ports, so the collision there is inferred; setting the dead port to the server's reproduces the same reason. The cell now keeps a socket bound to the dead port, not listening, so connections are refused and nothing else can bind it, picks a port other than the server's, and closes the socket just before the forwarder takes the port. The reason assertion prints the server log when it fails. test_a_store_outage_mid_download_leaves_the_restore_running_and_it_completes and the tarpit of test_a_stalled_s3_endpoint_holds_neither_the_listener_nor_the_reconciler had the same exposure: each bound a port picked before the server had bound its own, so the server could fail to start with "Address already in use". Both now exclude the server's port. _free_port takes the ports to avoid and is _closed_port with the socket closed. Signed-off-by: Scott Robinson <robinnsc@amazon.com>
a621190 to
398f1be
Compare
|
Thanks Lee. I've pushed 398f1be with all four changes, rebased on main 22ed10b. On that base the two files give SQLite 50 passed, 15 skipped and PostgreSQL 45 passed, 20 skipped (not as root), the lower counts being #620's, and the description now says so. The changed cells passed three more times on each build. Thanks for closing #983. |
What
Test-only fixes for three backup wire cells that failed intermittently on main and in the merge queue on 11 and 12 November, plus two cells with the same port exposure. No product code changes.
test_a_tampered_data_file_fails_the_restore_before_any_item(tests/test_backup_job.py): the restore job removes the target and then logs its FAILED line, and the cell read the log once as soon asDescribeTableansweredResourceNotFoundException. It now calls_restore_fails, as the two other failing-restore cells do: the helper waits for the target to go (failing if it is ever anything but CREATING), polls the log for the FAILED line for up to 15 s, and checks the reason and "the target was removed" on it. The cell's own GetItem probe is dropped, since a CREATING target answers no read. Failed in run 43242599309.test_a_row_that_lands_during_the_moves_sync_exits_1(tests/test_backup_job.py, PostgreSQL): the late row was reported only if it committed before the command's read of the other stores' rows, and the cell relied on listing 2,000 junk prefixes taking longer than its release of the held insert. The cell now drops the row of a second, complete backup before the move, so the move's sync adopts it, and a second trigger holds that adoption insert until the late row exists. The adoption is the sync's onlybackup_indexwrite and comes before the report's read, so the order no longer depends on the runner. After 30 s the trigger fails the insert with its own message. The junk prefixes are gone, and the cell also checks that the report's Adopted section lists exactly that backup. Failed in runs 42937487371, 43005024164 and 43272409754.TestSqlite::test_an_unreachable_s3_endpoint_starts_the_server_unhealthy_and_recovers(tests/test_backup_store_config.py): the "dead" endpoint port and the server's port were both picked with bind(0) and close. When they are equal, the server's S3 client reaches the server's own TLS listener, which answers plain HTTP with a 301, and the store check reportsfailed validationinstead ofunreachable, which is the failure in run 43108980074. The CI log does not show the ports, so the collision is inferred there; forcing it locally gives the same reason. The cell now keeps a socket bound to the dead port without listening (connections are refused and nothing else can bind it), never the server's port, and closes it just before the forwarder takes the port. The reason assertion prints the server log on failure.test_a_store_outage_mid_download_leaves_the_restore_running_and_it_completesand the tarpit inTestSqlite::test_a_stalled_s3_endpoint_holds_neither_the_listener_nor_the_reconciler: each bound a port picked before the server bound its own, so a collision made the server exit with "Address already in use". Both now exclude the server's port;_free_porttakes the ports to avoid and is_closed_portwith the socket closed.Why
These cells were the only intermittent failures in the backup suites in the last 100 Integration Tests runs (11 Nov 01:09 to 12 Nov 20:01 UTC). The other failures in that window were a PR's own tests (#618's branch), a GitHub artifact-service outage, and compile errors in the merge queue.
Testing done
Against release builds of this branch rebased on main 22ed10b (no Rust change), PostgreSQL 16 and moto on loopback, not as root:
python3 -m pytest tests/test_backup_store_config.py tests/test_backup_job.py -v -rP -p no:cacheprovider, as CI runs it: SQLite 50 passed, 15 skipped; PostgreSQL 45 passed, 20 skipped. Before fix(engine): validate numbers on every key and item path #620 replaced a 4-case cell with a 2-case one, the same run on main 8f932f3 gave 52/15 and 47/20, the counts of the CI runs above with the failed cell passing._restore_failsthe wrong reason text fails the tampered cell, so the helper still pins the hashing pass's reason.failed validation, CI's message; the store-outage and tarpit cells with the same collision fail with "Address already in use". With this branch neither helper can return the server's port.unreachableacross the reconciler's repeated checks, and the forwarder bound the port at once afterclose()50 of 50 times.mongodb-backup-storejob runstests/test_backup_job.pywithout an S3 endpoint, and the three changed cells there skip before the new code.Not changed here
run-postgres-storage-testsin run 43094482407 failedupdate_table_creates_a_vector_index_and_backfills_what_is_already_there(crates/storage-postgres/tests/vector_control_plane.rs:964, hold count 1, expected 0). The product marks the index ACTIVE in the catalog and then releases the hold in the data database, and the test reads the hold count once after seeing ACTIVE: the same read-before-write shape as the first cell. It is outside the backup suites, so it is left for a separate change.Checklist
cargo test --workspace): Python test changes onlycargo fmt --check): Python test changes onlycargo clippy -- -W clippy::pedantic): Python test changes onlyStoragetrait, 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
Breaking changes
None.
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.