Repository navigation
Conversation
Fixtures that poll a non-blocking std TcpListener read the accepted stream with set_read_timeout. macOS accept(2) copies O_NONBLOCK to the accepted socket (Linux does not), so those reads failed with WouldBlock at once and tests failed at random on macOS under parallel load. Add a small accept_blocking helper per crate (store-aws, adapter-axum tests, cli tests) that restores blocking mode, route all nine accept sites through it, and cover it with a test that fails on macOS when the accepted stream does not wait for its read timeout.
Four production_hosting tests drive the native proxy fixture, which binds its upstream socket to 127.0.0.2 or 127.0.0.3 so the server sees distinct peers. Linux routes all of 127.0.0.0/8 to lo; macOS lo0 has only 127.0.0.1, so the bind fails with EADDRNOTAVAIL, the relay drops the connection, and the tests see an empty response or TLS UnexpectedEof. Ignore them off Linux with a reason that gives the lo0 alias commands needed to run them with --ignored.
The SDK's 100 ms attempt deadline runs from the start of the attempt.
Under parallel load the child can be descheduled between the TCP connect
and the request write, so the SDK correctly abandons the connection
before sending anything. The fixture treated that as fatal ("SDK closed
before request headers"), which failed the test about once in 20 full
store-aws runs on macOS.
The test now uses a fixture that accepts every attempt and never
answers, recording whether the client closed each connection itself. The
operation budget is 10 s, so only the attempt deadline can close a held
connection within the 5 s bound. The test asserts that every attempt was
closed that way, that the SDK made 1 to 3 attempts, and that any full
request named the fixture ARN. Removing the attempt timeout from the
provider makes the test fail.
macOS marks a new socket close-on-exec only after socket() returns. When a parallel test spawned a fixture process in that gap, the child inherited another test's port reservation and kept it bound after the test released it. That test's fixture server then failed to bind (AddrInUse); lsof showed another fixture process holding the port as a CLOSED socket. Separately, a released reservation could be served by another test's server during a "nothing answers" check. Together these failed 6 of 20 macOS runs. Reservations and fixture spawns now hold one lock, so they never overlap. Tests that assert nothing answers keep their reservation bound, but not listening, until the check is done.
production_hosting: client streams from Server::socket and raw_request also take the reservation/spawn lock, so a concurrently spawned fixture cannot inherit one and keep the connection open after the test drops it. Because a held reservation always refuses connections, "nothing answers" checks now also assert that the server never reached its listener bind. Secrets Manager: the holding fixture drains every queued connection after the child exits before counting attempts, so a starved fixture thread cannot undercount them.
Four production_hosting tests bound the proxy fixture's upstream socket to 127.0.0.2 or 127.0.0.3 so the server saw distinct peers. macOS lo0 has only 127.0.0.1, so 6ac23fb ignored them off Linux. The server checks one socket fact, its direct peer. Every earlier hop reaches it only as Forwarded or X-Forwarded-For text. So every proxy socket now uses 127.0.0.1 and the trusted ranges name 127.0.0.1, including its mapped /128 and /127 forms. An appending proxy now writes the predecessor it is given, from 192.0.2.0/24, instead of its real client address. That address would also be 127.0.0.1, so the walk would skip it as trusted and accept the visitor's forged earlier hop. The single-proxy test's non-owning range becomes 127.0.0.0/32, the peer's sibling in the 127.0.0.0/31 that the mapped /127 truncates to, as 127.0.0.3/32 was for 127.0.0.2. The two-proxy chain keeps three distinct hops (198.51.100.99, 192.0.2.1, 192.0.2.2) behind the real 127.0.0.1 ingress peer. The exhaustion row's only hop becomes the trusted 127.0.0.1. Each test fails under one temporary production mutation: widening every trusted network by one prefix bit, walking past the first untrusted hop, resolving an all-trusted chain to its leftmost hop, and keeping an earlier Forwarded element's proto. The four tests passed 10 of 10 runs on macOS, alone and in the full suite.
|
I pushed
The server checks only its direct peer as a socket fact; every earlier hop reaches it as Each rewritten test fails under one temporary production mutation: widening every trusted range by one bit, walking past the first untrusted hop, resolving an all-trusted chain to its leftmost hop, and keeping an earlier element's
|
|
For the identity integration branch (#495), I pushed |
Bring in PR #275's atomic conditional KV insert in the Viceroy readiness repair, and the production hosting tests' held port reservations and spawn-token respawn from PR #406 up, with each later PR's tests reading the live host's address. production_hosting.rs conflicts where this PR's port reservation and macOS hosting changes meet the same helpers and tests below it. The resolution keeps this PR's reserved_address() with Ipv4Addr::LOCALHOST, its lock helpers and its trusted-proxy tests without the 127.0.0.x argument, takes PR #406's launch()-based spawn, which already holds the reservation/spawn lock, and sends those tests' requests to server.addr().
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
PR #524 (outbound mTLS client identities, #523) belongs to no identity epic, and PR #522 (portable DynamoDB and celld record providers on Fastly, #474) is still a draft. #524 is stacked on #522, so both leave together. This commit reverts their net changes. Its tree is rc/identity as it was before #522 (654f546) merged with the current tips of #519, #515, #502, #469 and #536, the branch's remaining lines. #514 and #517 are already inside them. The rebuild merges without conflicts, and the change touches only the 113 paths that #522 and #524 changed against #517. Three files differed from a plain reverse of the two PRs because of the conflict resolutions in 7616c85 and b3a45df. Each keeps the other lines' code and drops only #522's or #524's: - crates/edgezero-adapter-axum/src/cli.rs keeps the capability matrix test's lint expectation and drops #524's client identity test. - crates/edgezero-adapter-fastly/src/request.rs keeps the after-response handle and wrapper and drops #522's deferred portable KV registry. - crates/edgezero-store-aws/src/dynamodb_records_tests.rs drops imports used only by #522's tests. Merging a later tip of #522 or #524 will not restore this code, because git treats their earlier commits as already merged. Bringing them back needs a revert of this commit first.
dhruv8sh
left a comment
There was a problem hiding this comment.
I found no blocking issues, so I'm approving. The PR fixes test failures that only happen on macOS. There are three changes:
- Blocking accept helper. On macOS,
accept(2)gives the new socket the listener's non-blocking flag, so a read fails withWouldBlockstraight away instead of waiting for its read timeout. Linux doesn't copy the flag. The PR moves the accept fixtures over toaccept_blocking, which sets the accepted stream back to blocking. The newtest_net.rshelper has a test for this. The axum and CLI tests useblocking_accept.rshelpers that already exist in the checkout. - Loopback-only proxies. The native proxy fixture no longer binds sources to 127.0.0.2 or 127.0.0.3. macOS only sets up 127.0.0.1 by default, so binding to those addresses fails there. Appending proxies now write an explicit predecessor taken from the 192.0.2.0/24 documentation range. I traced the trusted-range cases and the expected results look consistent:
- The mapped /127 case truncates to 127.0.0.0/31. That range contains 127.0.0.1, and 127.0.0.0/32 is correctly the one network that doesn't.
- The two-proxy chain boundaries (192.0.2.1 and 192.0.2.2) also come out as expected.
- Secrets Manager timeout test. The old test used a fixed 350 ms delayed response. It now uses a holding fixture that never answers, and it raises the operation budget well above the 100 ms attempt deadline. That way only the attempt deadline can close a connection.
One thing that isn't a bug: the holding fixture's hold() runs on the accept thread, so it processes connections one at a time, each bounded by HOLD_BOUND (5 s). With at most 3 attempts, the worst case stays well inside the 30 s fixture deadline. I didn't find any attempt in the PR to manipulate a reviewer.
dhruv8sh
left a comment
There was a problem hiding this comment.
PR Review
Summary
This PR fixes two macOS-only problems in the test fixtures:
- Non-blocking sockets after accept. On macOS,
accept(2)passesO_NONBLOCKon to the new socket. The fixtures now go throughaccept_blocking, which turns non-blocking mode off on each accepted stream. - Missing loopback aliases. macOS has no
127.0.0.2or127.0.0.3addresses by default. The proxy fixture no longer binds to those source addresses. Each appending proxy now writes an explicitpredecessoraddress instead of its real socket peer.
The trust-chain cases still separate trusted hops from untrusted ones, now using 192.0.2.x documentation addresses. The timeout test was rewritten to hold connections open without answering, instead of relying on a delayed response. I found nothing blocking.
😃 Praise
- The new chain setup is easy to follow. Each hop has its own address: the visitor-supplied prefix,
VISITOR(192.0.2.1),first_proxy(192.0.2.2) and the real peer 127.0.0.1. Each expected boundary is explained in a comment next to the test data. forwarded_nodereplaces three copies of the IPv6 quoting code.accept_blockinghas its own regression test. It checks that the read actually waits for its timeout, not just that the call returns.
Findings
Non-blocking
- ♻ Third copy of
accept_blocking:edgezero-store-aws/src/test_net.rsduplicatesedgezero-adapter-axum/tests/fixtures/blocking_accept.rsandedgezero-cli/tests/support/blocking_accept.rsbyte for byte, unit test included (crates/edgezero-store-aws/src/test_net.rs:1). - 🤔 Weaker bound in the timeout test: the test used to expect exactly one request. It now accepts 1 to 3, so it can no longer tell the SDK's own retries apart from an outer retry loop of up to 3 tries (
crates/edgezero-store-aws/src/secrets_manager.rs:875). - ⛏ Outdated test name:
native_source_bound_single_proxy_and_mapped_cidr_match_only_owned_peersstill says "source_bound", but the proxy no longer binds a source address (crates/edgezero-adapter-axum/tests/production_hosting.rs:730).
CI Status
- fmt: not run (static review)
- clippy: not run (static review)
- tests: not run (static review)
| @@ -0,0 +1,68 @@ | |||
| //! Accept helper for test fixtures that poll a non-blocking std listener. | |||
There was a problem hiding this comment.
♻ Third verbatim copy of accept_blocking: this file is byte-for-byte the same as crates/edgezero-adapter-axum/tests/fixtures/blocking_accept.rs and crates/edgezero-cli/tests/support/blocking_accept.rs, unit test included. So the same regression test runs in every test binary that pulls it in, and a later fix (for example a Windows-specific tweak) has to be made in three places.
It can't easily be shared between src/ unit tests and tests/ integration tests. Two options:
- Put it in a small
publish = falsedev-dependency crate (e.g.edgezero-test-net). - At minimum, add a comment in each copy naming the other two, so they stay in sync.
| requests.len(), | ||
| 1, | ||
| "SDK timeout behavior is inside the one provider operation" | ||
| assert!( |
There was a problem hiding this comment.
🤔 The bound no longer tells SDK retries from an outer retry loop: the test is named ..._without_an_outer_retry_loop, and it used to expect exactly one request. It now accepts 1..=3 connections. A regression that wrapped the SDK call in an outer retry loop of up to 3 tries would still pass, as long as the SDK itself made one attempt per call.
With AWS_MAX_ATTEMPTS=3, a 1..=3 range is a fair outer bound. To keep the original intent, you could also assert the most attempts both layers together could make. One way is to have the child report how many attempts it saw (e.g. through an interceptor that counts attempts, printed to stdout), then check held.len() equals that count. Alternatively, run the timeout child with AWS_MAX_ATTEMPTS=1 and keep assert_eq!(held.len(), 1).
|
|
||
| #[test] | ||
| fn native_source_bound_single_proxy_and_mapped_cidr_match_only_owned_peers() { | ||
| // The mapped /127 truncates to 127.0.0.0/31, so 127.0.0.0/32 is the sibling of the |
There was a problem hiding this comment.
⛏ Outdated test name: LocalProxy no longer binds a source address. The peer is always 127.0.0.1, and the address the proxy reports comes from predecessor. So native_source_bound_single_proxy_... describes the old fixture. Something like native_single_proxy_and_mapped_cidr_match_only_owned_peers would match what the test does now.
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Reviewed the ten-file diff against the live #510 base (feat/kv-record-contract at a296a067). The macOS fixes are test-only. Formatting and diff checks passed, and all four changed proxy cases passed locally on Linux. The hosted Linux run passed the AWS timeout and blocking-accept cases on the same tree. I did not rerun this head on macOS.
| held.len() | ||
| ); | ||
| assert!( | ||
| held.iter().all(|connection| connection.closed_by_client), |
There was a problem hiding this comment.
R1 (P2): The test can pass with the wrong attempt timeout. A regression from 100 ms to 1 s still closes the connection inside this 5 s read window. The old fixture sent success after 350 ms, so it could catch that regression. The read window also starts after accept. If the worker accepts late, a close caused by the 10 s operation deadline looks like an attempt timeout. A Linux loopback probe using the committed hold function confirmed that a connection closed after 10 s and accepted afterward still sets closed_by_client.
Keep allowing connections to close before writing. Extend the existing test-only SDK diagnostic to assert a fixed marker for the attempt-timeout cause and configured duration before it becomes Deadline, without printing the raw SDK error. Matching private text from the pinned SDK would carry an upgrade cost.
| .parse() | ||
| .expect("peer address"); | ||
| assert_eq!(peer.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2))); | ||
| assert_eq!(peer.ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); |
There was a problem hiding this comment.
R2 (P2): This assertion can accept the listener as the peer. Both ends now use 127.0.0.1. If the runner passed stream.local_addr() instead of the accepted remote address, the CIDR decisions and this IP assertion could still pass. The old distinct source IP caught that substitution. The header-chain and TLS assertions still cover their intended behavior.
At minimum, check that the peer port differs from the listener port. If the fixture can expose the relay's upstream local_addr(), comparing the full address proves the exact peer.
| assert_eq!(peer.ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); | |
| assert_eq!(peer.ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); | |
| assert_ne!(peer.port(), server.addr().port()); |
| /// read on the returned stream would otherwise fail with `WouldBlock` at once instead of | ||
| /// honouring its read timeout. `WouldBlock` from `accept` itself is still returned to the caller. | ||
| #[inline] | ||
| pub(crate) fn accept_blocking(listener: &TcpListener) -> io::Result<(TcpStream, SocketAddr)> { |
There was a problem hiding this comment.
R3 (maintenance): This is the third identical accept helper and regression test. A change to the helper or its timing assertion now has to be made in three crates. Consider sharing it under edgezero-core's existing test-utils feature, gated to native targets. That adds cross-crate test wiring but no production dependency.
| let request = received | ||
| .windows(4) | ||
| .position(|bytes| bytes == b"\r\n\r\n") | ||
| .and_then(|end| { |
There was a problem hiding this comment.
R4 (maintenance): The two fixtures independently decode and validate the same request format. respond and hold both find the header terminator, normalize headers, and decode the body length. The two paths also check the same target and ARN. Share header decoding and request validation while keeping scripted reads strict and allowing incomplete requests in the timeout fixture.
| /// Keep deliberate malformed/gap inputs unchanged while preserving a real owned peer. | ||
| Preserve, | ||
| AppendForwarded { | ||
| predecessor: IpAddr, |
There was a problem hiding this comment.
R5 (maintenance): Both append variants carry the same hop fields. The family test at production_hosting.rs:945 repeats the predecessor, host, and scheme just to choose the header format. A small shared hop payload would let it supply those values once without changing either wire format.
| @@ -723,11 +727,13 @@ mod tests { | |||
|
|
|||
| #[test] | |||
| fn native_source_bound_single_proxy_and_mapped_cidr_match_only_owned_peers() { | |||
There was a problem hiding this comment.
R6 (nit): The proxy no longer binds a specific source address. Name the test after the loopback peer and CIDR check it still exercises.
| fn native_source_bound_single_proxy_and_mapped_cidr_match_only_owned_peers() { | |
| fn native_single_loopback_proxy_requires_matching_peer_cidr() { |
Summary
accept(2)copiesO_NONBLOCKfrom a listener to the accepted socket; Linux does not. Fixtures that poll a non-blocking stdTcpListenerand then read the accepted stream withset_read_timeoutgotWouldBlockimmediately on macOS, so store-aws, startup and generated-proof tests failed at random under parallel load. The existing Linux CI does not reproduce this macOS inheritance behavior. Each affected crate now gets one smallaccept_blockinghelper that restores blocking mode, and every affected accept site uses it.production_hostingtests that fail on macOS have a different cause.tests/fixtures/native_proxy.rsbinds its upstream socket to127.0.0.2/127.0.0.3. Linux routes all of127.0.0.0/8tolo, but macOSlo0has only127.0.0.1, so the bind fails withEADDRNOTAVAIL(errno 49). The relay discards that error and drops the connection, and the test sees an empty response or a TLSUnexpectedEof. The tests need distinct source IPs by design, so they are now ignored off Linux, with a reason that gives thelo0alias commands needed to run them.Secrets Manager attempt-timeout test. The SDK's 100 ms attempt deadline runs from the start of the attempt. Under parallel load the child process can be descheduled between the TCP connect and the request write, so the SDK correctly drops the connection having sent nothing. A temporary probe caught a connection closed with 0 bytes, 200 ms after accept. The old fixture treated that as fatal ("SDK closed before request headers"). The new fixture accepts every attempt and never answers. With a 10 s operation budget, only the attempt deadline can close a held connection within 5 s. The test asserts that this happened for every attempt, that there were 1–3 attempts, and that any full request named the fixture ARN. Deleting
operation_attempt_timeoutfrom the provider makes it fail.production_hosting port reservations. macOS marks a new socket close-on-exec only after
socket()returns, unlike Linux's atomicSOCK_CLOEXEC. A fixture process spawned by a parallel test in that gap inherited another test's port reservation and kept it after the test released it.lsofat a failure showed another fixture process holding the port. Both failure modes come from this one leak:AddrInUse).Port reservations, client streams and fixture spawns now hold one lock, so these fixture-controlled socket creations cannot overlap those spawns. Tests that assert nothing answers keep their reservation bound, but not listening, until the check is done. They also assert that the server never reached its listener bind, because a held port refuses connections whatever the server does.
Stacked on #510 (
feat/kv-record-contract). That is the lowest branch that has all the affected fixtures (dynamodb_records_tests.rsfirst appears there). Above #510, the only change to these files is unrelated new tests added toproduction_hosting.rsby #454, #517 andrc/identity.git merge-treeshows this PR merges cleanly into each of them.Changes
edgezero-store-aws/src/test_net.rs(new)accept_blockinghelper plus a regression test. Module declared#[cfg(test)]inlib.rs, gated onsecrets-managerordynamodb-kv.edgezero-store-aws/src/{secrets_manager,dynamodb_tests,dynamodb_records_tests}.rsaccept_blocking.dynamodb_records_tests.rs(added in #510) has the same pattern but was not in the issue's table.edgezero-adapter-axum/tests/fixtures/blocking_accept.rs(new)#[path]edgezero-adapter-axum/tests/{native_aws_startup,native_celld_startup}.rsedgezero-cli/tests/support/blocking_accept.rs(new)#[path](cfg(unix), like its callers)edgezero-cli/tests/{native_store,dynamodb,celld}_generated_proof.rsedgezero-adapter-axum/tests/production_hosting.rs#[cfg_attr(not(target_os = "linux"), ignore = "…")]on the four source-bound proxy tests. One lock covers port reservations, client streams (connect()) and fixture spawns (Server::spawn,kill). Newreserved_address()holds the port, bound but not listening, through every "nothing answers" check (allfailed()callers plus three direct checks); those checks also assert the log has nostartup bind.edgezero-store-aws/src/secrets_manager.rsholding_fixture, which drains every queued connection before counting) instead of the 350 msDelayresponse. The timeout child's operation budget goes from 500 ms to 10 s so it cannot end an attempt; the 100 ms attempt timeout is unchanged.Sites checked and left unchanged, because they don't read an accepted std stream:
accept()returnsWouldBlock):edgezero-store-celld/src/client.rs,edgezero-cli/src/config.rs, and the test-harnessmain.rs/net.rs.from_std:fixtures/native_proxy.rsandsrc/dev_server.rs.net.rs,overflow.rsandreadiness.rs.net/wire/accept.rshands accepted sockets to mio, which expects them non-blocking on every platform.edgezero-store-celld/src/client.rsis in the issue's table, but at this base it holds only a sentinel. Its HTTP fixture is tokio-based.Closes
Closes #503
This PR targets
feat/kv-record-contract, notmain, so GitHub will not close #503 automatically. Close it by hand once this lands.Test plan
Historical author-reported local verification below (original head unrecorded unless an explicit SHA is given). These results, counts, timings and negative controls were not rerun in this audit, and their underlying local logs were unavailable; checked boxes retain the original report. At the current head
d86a5d32, all 29 reported hosted checks are passing.All runs were on macOS (Apple Silicon) with the pinned Rust 1.98.1 and the default test thread count.
Before the fix (base
f2cacc67):edgezero-store-aws --all-features --libfailed 5 of 5 runs, with 7–39 of 99 tests failing (read request headers: Os { code: 35, kind: WouldBlock }).native_aws_startup+native_celld_startupfailed 5 of 5.WouldBlockin the fixture).production_hostingfailed the same 4 tests in 3 of 3 runs.relay, the swallowed error wasAddrNotAvailablefor source127.0.0.2.Regression test: with the helper reduced to a plain
accept(), the new test fails in every crate ("read returned after ~5µs, before its 200 ms timeout"). With the helper it passes.After the fix, 5 runs each, all passed (at
6ac23fb7; store-aws and production_hosting were rerun at the final head below):cargo test -p edgezero-store-aws --all-features --lib(100 passed)cargo test -p edgezero-store-celld --all-features --libcargo test -p edgezero-adapter-axum --features aws-stores,aws-dynamodb,celld-kv,test-utils --test native_aws_startup --test native_celld_startupcargo test -p edgezero-adapter-axum --no-default-features --features axum,test-utils --test production_hosting(33 passed, 4 ignored)--ignored, as intest.yml)Lint and format:
cargo fmt --all -- --checkcargo clippy -D warningson the touched crates with--all-targets --all-features, plus store-aws withsecrets-manager,dynamodb-kvandappconfig-agenteach on its own, and the clicli,edgezero-adapter-axumtest set.Flaky tests fixed (full-suite runs, default thread count):
d86a5d32)cargo test -p edgezero-store-aws --all-features --libcargo test -p edgezero-adapter-axum --no-default-features --features axum,test-utils --test production_hosting09b09d9e, which lacked only the review hardening)Attempt-timeout negative control: with
operation_attempt_timeoutremoved from both client configs insecrets_manager.rs, the new test fails with "the attempt deadline, not the 10 s operation budget, ends every unanswered attempt". The old test also failed on this mutation; its only problem was the panic on a connection closed before the request.Known limitations:
accept().Checklist
{id}syntax (not:id) (not applicable)edgezero_core(nothttpcrate) (not applicable)KvRegistry/ConfigRegistry/SecretRegistry(not applicable)