Skip to content

Fix three Windows CI flakes: replay tests, HTTP/2 body close, WebSocket 1009 - #2426

Merged
hyperxpro merged 4 commits into
AsyncHttpClient:mainfrom
maygemdev:pavel-ptashyts/fix-flaky-failed-replay-test
Dec 6, 2026
Merged

hyperxpro merged 4 commits into
AsyncHttpClient:mainfrom
maygemdev:pavel-ptashyts/fix-flaky-failed-replay-test

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This fixes three Windows CI flakes, one commit each, plus one commit for the review. All three come from the same Windows behaviour: a file or connection that one side still holds when the other acts on it.

1. FailedReplayHttp2Test and FailedReplayTest (test-only)

FailedReplayHttp2Test.aReplayThatCannotBeBuiltFailsTheRequest (added by #2415) fails on windows-latest in every Build PR run since that merge. The test server deleted the request body file before the client's last write had closed it. Windows refuses to delete an open file, so the server handler threw, the stream was reset, and the request failed with an IOException instead of the expected IllegalArgumentException. FailedReplayTest has the same race over HTTP/1.1.

The servers no longer delete the file. A ResponseFilter on the client deletes it when the 307 arrives, after the write has closed it. What the tests assert is unchanged.

Test (Windows 11, JDK 25, 500 runs under load) Before After
FailedReplayHttp2Test 22 failed 0
FailedReplayTest 32 failed 0

2. Http2BodyWriter: close the body source before failing the request

When reading the next chunk of an HTTP/2 body failed, pump called future.abort(t) before finish(t) closed the source. The caller was woken while the file was still open, so on Windows it could not delete it (Http2StreamingBodyFlowControlTest hit this on JDK 17). The source is now closed first, through a closeSource() that runs once. The future still fails before the stream is closed, as #2401 requires, and Http2BodyWriterTest asserts that order.

Evidence (Windows 11, JDK 25, under load): 5 of 600 failed before, 0 of 600 after.

3. WebSocketHandler: leave closing to the server after a 1009

On a message over the buffer or inflate limit, the client sent 1009 and closed the connection right away with the rest of the server's message unread. The reset could make the server lose the 1009 and report 1006.

The client now sends the 1009 alone and, as RFC 6455 section 7.1.1 asks, waits up to 10 seconds for the server to close, discarding inbound data meanwhile. While it waits:

  • no frame reaches the listener after onError;
  • isOpen() is false and sends fail (new internal NettyWebSocket.markClosing());
  • any other error only closes the connection, so onError is called once;
  • the permit is released before onError, so a reconnect with maxConnections(1) is not refused.

If the big message arrives with the 101, the upgrade future fails and onOpen is not called.

Behaviour change: after a 1009 the listener now gets onClose (1006) once the server closes. Before, it never got onClose.

Evidence (Windows 11, JDK 25, under load): 8 and 12 of 300 failed before, 0 of 300 after. With the review changes, 900 of 900 passed.

AI disclosure

Claude Code on behalf of Pavel Ptashyts. Each commit includes Co-Authored-By per AGENTS.md.

Test plan

  • mvnw.cmd -B -ntp clean verify -Dgpg.skip=true on JDK 11: BUILD SUCCESS, 2,491 tests, 0 failures; Revapi passed.
  • Before/after runs above on Windows 11, JDK 25.
  • CI after the review changes: all 13 jobs pass, including the four windows-latest ones.

🤖 Generated with Claude Code

pavel-ptashyts and others added 3 commits December 1, 2026 08:22
FailedReplayHttp2Test and FailedReplayTest had their server delete the
request body file as soon as it had read the body. The client closes
the file only when its last write of the body completes, and the server
can read that body before the client's write listener runs. Windows
refuses to delete a file that is still open, so the server's delete
failed now and then: over HTTP/2 the stream was reset and the request
failed with that IOException, over HTTP/1.1 Jetty answered 500. This
made FailedReplayHttp2Test fail on windows-latest in every Build PR
run on main since AsyncHttpClient#2415.

A response filter now deletes the file on the client when the 307
arrives. It runs on the event loop that wrote the body, after that
write has closed the file, so the delete no longer races it. The tests
still prove that a replay that cannot be built fails the request with
the IllegalArgumentException of the build, after one replay, and that
the client serves requests afterwards.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When reading the next chunk of an HTTP/2 request body failed, for
example because a file body got shorter than its announced length,
Http2BodyWriter failed the request future first and closed the body
source only afterwards. A caller woken by that failure could then find
the file still open: on Windows, deleting it failed with "The process
cannot access the file because it is being used by another process".
Http2StreamingBodyFlowControlTest hit this in its cleanup on
windows-latest.

The source is now closed before the future fails. The future still
fails with the source's error before the stream is closed, so it is
neither replaced by the closed stream nor replayed.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a WebSocket message went over the buffer or inflate limit, the
client sent a 1009 close frame and closed the connection at once. What
the server was still sending stayed unread, so closing reset the
connection, and the server could lose the close frame and report 1006.
WebSocketMessageTooBigTest failed this way on windows-latest. The
handler also sent a second close frame, 1000, after the 1009.

The client now sends the 1009 alone and, as RFC 6455 section 7.1.1
asks of a client, leaves closing the connection to the server. It
discards what the server still sends meanwhile, and closes the
connection itself if the server has not done so within 10 seconds. The
listener still gets onError, then onClose once the connection is gone.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pavel-ptashyts pavel-ptashyts changed the title Delete the body file from the client in replay tests Fix three Windows CI flakes: replay tests, HTTP/2 body close, WebSocket 1009 Dec 1, 2026
Review of the 1009 change: while the client waited for the server to
close, a second error could call onError again and skip onClose,
frames the decoder still held reached the listener after onError, the
WebSocket still accepted sends, and the connection kept its permit, so
a reconnect from onError with maxConnections 1 was refused. A message
too big that came with the 101 was reported to no listener, and
onOpen followed.

Now further errors only close the connection, held frames are
dropped, the WebSocket is marked closing, and the permit is released
before onError, as abort() does. With the 101, the upgrade fails like
any other failed upgrade: onError, no onOpen and no onClose, and the
frames buffered for it are released.

Http2BodyWriterTest now asserts that the source is closed before the
request fails and the stream closes.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hyperxpro
hyperxpro merged commit 31f5cea into AsyncHttpClient:main Dec 6, 2026
13 checks passed
@pavel-ptashyts
pavel-ptashyts deleted the pavel-ptashyts/fix-flaky-failed-replay-test branch December 6, 2026 13:25
hyperxpro added a commit that referenced this pull request Dec 6, 2026
Motivation:

After a 1009, #2426 waits up to 10 seconds for the server to close, but
releases the connection permit as soon as the close frame is sent. A
server that never closes lets a reconnecting client go past
`maxConnections`. Frames the decoder already holds are still parsed, so
a bad frame behind the big message makes Netty send a second close frame
and close the connection first. The server's own close frame is dropped,
so the client waits the full 10 seconds and reports 1006.

Modification:

Keep the permit until the connection is closed. Replace the decoder
after the 1009 with one that does not close on a protocol violation, and
ignore decoder errors while waiting. Handle the server's close frame
while waiting. Track the closing state with a channel attribute instead
of scanning the pipeline for every frame.

Result:

`maxConnections` holds after a 1009, the client sends one close frame
and leaves closing to the server, and a close frame from the server ends
the wait with its code. A reconnect from `onError` with `maxConnections`
set is now refused until the old connection closes.
pavel-ptashyts added a commit to maygemdev/async-http-client that referenced this pull request Dec 6, 2026
The windows-latest jobs of this pull request failed in tests that
main has since fixed in AsyncHttpClient#2426 (replay tests deleting an open body
file, the HTTP/2 body close order and the WebSocket 1009 close).
Failed jobs cannot be re-run from a fork, so merge main to run CI
on a tree that has the fixes. No change to this branch's own work.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
pavel-ptashyts added a commit to maygemdev/async-http-client that referenced this pull request Dec 6, 2026
The windows-latest jobs of this pull request failed in tests that
main has since fixed in AsyncHttpClient#2426 (replay tests deleting an open body
file, the HTTP/2 body close order and the WebSocket 1009 close).
Failed jobs cannot be re-run from a fork, so merge main to run CI
on a tree that has the fixes. No change to this branch's own work.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
pavel-ptashyts added a commit to maygemdev/async-http-client that referenced this pull request Dec 6, 2026
The windows-latest jobs of this pull request failed in tests that
main has since fixed in AsyncHttpClient#2426 (replay tests deleting an open body
file, the HTTP/2 body close order and the WebSocket 1009 close).
Failed jobs cannot be re-run from a fork, so merge main to run CI
on a tree that has the fixes. No change to this branch's own work.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
pavel-ptashyts added a commit to maygemdev/async-http-client that referenced this pull request Dec 6, 2026
The windows-latest jobs of this pull request failed in tests that
main has since fixed in AsyncHttpClient#2426 (replay tests deleting an open body
file, the HTTP/2 body close order and the WebSocket 1009 close).
Failed jobs cannot be re-run from a fork, so merge main to run CI
on a tree that has the fixes. No change to this branch's own work.

Claude Code on behalf of Pavel Ptashyts

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

2 participants