Skip to content

fix(kawa-h1): clear the sticky-session answer when reusing a keep-alive slot - #1833

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h1-keepalive-sticky-reset
Oct 3, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h1-keepalive-sticky-reset

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Fixes #1822

Problem

On one HTTP/1 keep-alive connection, a request to a sticky frontend followed by a request to a frontend that does not stick: the second request reaches its own backend, but its response carries the first request's Set-Cookie: SOZUBALANCEID=….

CAUSE: lib/src/protocol/kawa_h1/editor.rs HttpContext::reset leaves sticky_session in place -> lib/src/protocol/mux/router.rs backend_from_request writes sticky_session only when the frontend sticks, so the non-sticky request inherits the stale value -> SYMPTOM: editor.rs on_response_headers emits Set-Cookie for any retained sticky_session that differs from sticky_session_found (None on the second request).

Fix

HttpContext::reset clears sticky_session, and its postcondition debug_assert! now checks it. Other fields that survive reset (cluster_id, backend_id, ...) are left alone: as the issue says, each needs its own path-specific oracle before being claimed as a defect.

HTTP/2 is not affected: Context::create_stream (lib/src/protocol/mux/mod.rs) builds a fresh HttpContext::new(...) for every stream and assigns it to stream.context on the recycled-slot path too; the only HttpContext::reset caller is the H1 keep-alive branch in lib/src/protocol/mux/h1.rs.

Tests

  • Unit reset_clears_the_sticky_session_answer_of_the_previous_request (editor.rs): a response edited with a sticky answer carries the cookie (premise), and after reset the next response carries none.
  • e2e test_keep_alive_does_not_carry_a_sticky_cookie_over (e2e/src/tests/tests.rs): sticky cluster_0 on localhost, non-sticky cluster_1 on plain.localhost, one keep-alive client connection.
  • test_reset_preserves_connection_state asserted that reset keeps sticky_session; that assertion encoded the defect reported here, so its setup line and assertion are removed (the rest of the test is unchanged).

RED on bd19a78e (before the fix):

assertion `left == right` failed: reset must clear the previous request's sticky-session answer
  left: Some("sticky-a")
 right: None
plain response: "HTTP/1.1 200 OK\r\nContent-Length: 1\r\nConnection: keep-alive\r\nSet-Cookie: SOZUBALANCEID=sticky_cluster_0-0; Path=/\r\nSozu-Id: ...\r\n\r\nb"
the plain request must not carry the sticky request's cookie

Validation (local)

  • cargo +nightly fmt --check -> exit 0
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings -> exit 0
  • RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -> exit 0
  • cargo +1.93.1 test -p sozu-lib --lib --all-features --locked -> 1593 passed; 0 failed
  • cargo +1.93.1 test -p sozu-e2e --features opentelemetry,splice,simd -- test_keep_alive_does_not_carry_a_sticky_cookie_over test_stick test_keep_alive_rotates_request_id -> 3 passed; -- sticky affinity -> 11 passed (full e2e suite left to CI)
  • python3 .github/scripts/check_doc_citations.py --root . --base origin/main -> all OK

Docs: lib/src/protocol/kawa_h1/LIFECYCLE.md invariant 4, doc/lifetime_of_a_session.md §6.6, CHANGELOG (Unreleased / Fixed).

…ve slot

HttpContext::reset kept sticky_session across the requests of one
HTTP/1 keep-alive connection. backend_from_request writes it only when
the request's frontend sticks, and on_response_headers answers any value
left there with a Set-Cookie, so a request to a frontend that does not
stick, sent after one to a sticky frontend on the same connection,
reached its own backend but was answered with the previous request's
SOZUBALANCEID cookie. reset now clears it.

HTTP/2 is not affected: Context::create_stream builds a fresh
HttpContext for every stream, recycled slots included.

The assertion of test_reset_preserves_connection_state that reset keeps
sticky_session encoded the defect and is removed; the new unit test and
e2e test_keep_alive_does_not_carry_a_sticky_cookie_over pin the fix.

Fixes #1822

Signed-off-by: Florentin Dubois <[email protected]>
…a pin

The cookie is answered on a frontend that does not stick, whose router
ignores it, so it names a backend of another cluster without pinning
the client to it.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit f8dddbb into main Oct 3, 2026
23 checks passed
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.

Clear sticky-session state when reusing an HTTP/1 keep-alive slot

1 participant