GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Arm force-close timeout when an inbound CLOSE frame is echoed by normanmaurer · Pull Request #17574 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Sep 21, 2026

Copy link
Copy Markdown
Member

Motivation:

WebSocketServerProtocolHandler.decode() writes the CLOSE echo directly
via WebSocketServerHandshaker.close(), bypassing this handler's own
write()/close() overrides where forceCloseTimeoutMillis was armed. If
the peer stops draining its socket, the echo write never completes and
the channel, its file descriptor and buffers are pinned forever.

Modifications:

Arm the timeout explicitly after the echo write is issued, and also
from a new flush() override so a bare write(CloseWebSocketFrame) not
followed by close() gets the same protection. The timeout is applied
after the write/flush attempt, not before, so a write that completes
synchronously never races the deadline.

Result:

Awalys close the channel even when the remote peer stops reading

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@normanmaurer
Arm force-close timeout when an inbound CLOSE frame is echoed
34b6a4b
Motivation:

WebSocketServerProtocolHandler.decode() writes the CLOSE echo directly
via WebSocketServerHandshaker.close(), bypassing this handler's own
write()/close() overrides where forceCloseTimeoutMillis was armed. If
the peer stops draining its socket, the echo write never completes and
the channel, its file descriptor and buffers are pinned forever.

Modifications:

Arm the timeout explicitly after the echo write is issued, and also
from a new flush() override so a bare write(CloseWebSocketFrame) not
followed by close() gets the same protection. The timeout is applied
after the write/flush attempt, not before, so a write that completes
synchronously never races the deadline.

Result:

Awalys close the channel even when the remote peer stops reading
@normanmaurer
normanmaurer requested a review from yawkat September 21, 2026 14:46
@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 21, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Sep 21, 2026
@xhae123

xhae123 commented Sep 22, 2026

Copy link
Copy Markdown

I was reading through the new flush() timeout path and wondered about the bare outbound CLOSE case mentioned in the PR description.

The new regression test exercises the inbound CLOSE echo path. Would it make sense to also add a test that stalls writeAndFlush(new CloseWebSocketFrame()) without calling channel.close(), advances past forceCloseTimeoutMillis, and asserts that the channel is closed?

Unless I am missing another listener, applyCloseSentTimeout() only fails closeSent when the deadline fires. The close() path attaches a listener that calls ctx.close(...), and WebSocketServerHandshaker.close(...) also attaches a close listener, but a bare write does not seem to do either. In that case the promise may fail while the channel remains open.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
Close the channel directly from the force-close timeout
308afa0
A bare write(CloseWebSocketFrame) with no subsequent close() call
never attached a listener that would close the channel once the
force-close timeout failed closeSent, so the deadline had no effect
on that path even though it fired. Have the timeout task close the
channel itself instead of relying on other code paths to do so.
@normanmaurer

normanmaurer commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

I was reading through the new flush() timeout path and wondered about the bare outbound CLOSE case mentioned in the PR description.

The new regression test exercises the inbound CLOSE echo path. Would it make sense to also add a test that stalls writeAndFlush(new CloseWebSocketFrame()) without calling channel.close(), advances past forceCloseTimeoutMillis, and asserts that the channel is closed?

Unless I am missing another listener, applyCloseSentTimeout() only fails closeSent when the deadline fires. The close() path attaches a listener that calls ctx.close(...), and WebSocketServerHandshaker.close(...) also attaches a close listener, but a bare write does not seem to do either. In that case the promise may fail while the channel remains open.

Good catch... Pushed a fix. PTAL again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

Test failure fixed by #17590

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer requested a review from chrisvest September 22, 2026 14:45
@xhae123

xhae123 commented Sep 23, 2026

Copy link
Copy Markdown

Good catch... Pushed a fix. PTAL again

looks good to me 👏

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chrisvest
chrisvest reviewed Sep 23, 2026
View reviewed changes
Comment thread codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer added 3 commits September 26, 2026 04:01
@normanmaurer
Cascade closeSent() instead of overwriting an in-flight promise
c4eb1c0
An application-initiated close (via ctx.close(), which arms the
force-close deadline) can race with the peer's own CLOSE frame
arriving concurrently. decode() unconditionally called closeSent(),
silently replacing the field. Since the scheduled deadline task reads
the closeSent field rather than a captured promise, it would then
watch the wrong promise, leaving the original caller's close promise
hanging forever.

closeSent() now cascades onto the existing promise instead of
replacing it when one is already in flight, so both promises complete
once the deadline fires.
@normanmaurer
Merge branch '4.2' into ws-close-1b430108
1b1e5fd
@normanmaurer
Use 10 seconds as default
7c04c3b
@normanmaurer normanmaurer closed this Sep 29, 2026
@normanmaurer
normanmaurer deleted the ws-close-1b430108 branch September 29, 2026 14:50
@normanmaurer
normanmaurer restored the ws-close-1b430108 branch September 29, 2026 14:51
@normanmaurer normanmaurer reopened this Sep 29, 2026
chrisvest
chrisvest approved these changes Sep 29, 2026
View reviewed changes
@normanmaurer
Merge branch '4.2' into ws-close-1b430108
dd650fb
@testlens-app

testlens-app Bot commented Oct 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) ❌ 4% 🟡

🏷️ Commit: dd650fb
▶️ Tests: 401959 executed
⚪️ Checks: 26/26 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:368)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:194)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:172)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:158)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:155)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:155)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Rerun Controls

Select tests to mute in this pull request:

  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo)

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer merged commit 1330f40 into 4.2 Oct 1, 2026
26 of 27 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer deleted the ws-close-1b430108 branch October 1, 2026 14:13
@netty-project-bot

netty-project-bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Port 4.1: #17710
Port 5.0: #17712

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer added a commit that referenced this pull request Oct 2, 2026
@normanmaurer
Port 5.0: Arm force-close timeout when an inbound CLOSE frame is echo…
c2954c4
…ed (#17574) (#17712)

Motivation:

WebSocketServerProtocolHandler.decode() writes the CLOSE echo directly
via WebSocketServerHandshaker.close(), bypassing this handler's own
write()/close() overrides where forceCloseTimeoutMillis was armed. If
the peer stops draining its socket, the echo write never completes and
the channel, its file descriptor and buffers are pinned forever.

Modifications:

Arm the timeout explicitly after the echo write is issued, and also
from a new flush() override so a bare write(CloseWebSocketFrame) not
followed by close() gets the same protection. The timeout is applied
after the write/flush attempt, not before, so a write that completes
synchronously never races the deadline.

Result:

Awalys close the channel even when the remote peer stops reading
normanmaurer added a commit that referenced this pull request Oct 2, 2026
@normanmaurer
Port 4.1: Arm force-close timeout when an inbound CLOSE frame is echo…
e7de11e
…ed (#17574) (#17710)

Motivation:

WebSocketServerProtocolHandler.decode() writes the CLOSE echo directly
via WebSocketServerHandshaker.close(), bypassing this handler's own
write()/close() overrides where forceCloseTimeoutMillis was armed. If
the peer stops draining its socket, the echo write never completes and
the channel, its file descriptor and buffers are pinned forever.

Modifications:

Arm the timeout explicitly after the echo write is issued, and also
from a new flush() override so a bare write(CloseWebSocketFrame) not
followed by close() gets the same protection. The timeout is applied
after the write/flush attempt, not before, so a write that completes
synchronously never races the deadline.

Result:

Awalys close the channel even when the remote peer stops reading
@jguerra jguerra mentioned this pull request Oct 7, 2026
WebSocket close handshake fails with "promise already done" with netty 4.2.19 #17776
Closed
@sharanggupta sharanggupta mentioned this pull request Oct 7, 2026
Don't echo a CLOSE frame once our own CLOSE frame was already sent #17777
Closed
@Asthenia0412 Asthenia0412 mentioned this pull request Oct 12, 2026
fix(codec-http): avoid "promise already done" in WebSocket close handshake #17786
Closed
@chrisvest chrisvest removed needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Oct 20, 2026
@normanmaurer normanmaurer mentioned this pull request Oct 21, 2026
Fix server-initiated WebSocket close handshake failing with "promise already done" #17983
Merged
normanmaurer added a commit that referenced this pull request Oct 22, 2026
@normanmaurer
Fix server-initiated WebSocket close handshake failing with "promise …
7a6f630
…already done" (#17983)

Motivation:

Since #17574, `WebSocketProtocolHandler.closeSent(promise)` cascades the
outcome of an already recorded close promise onto the new one. When the
server initiates the close handshake by writing a `CloseWebSocketFrame`
and the peer responds with its own close frame,
`WebSocketServerProtocolHandler.decode()` creates a new promise, passes
it to `closeSent()` and then to `WebSocketServerHandshaker.close()`.
As our own close frame was already written, the new promise is completed
immediately, so the write in `close()` fails with
`IllegalArgumentException: promise already done` and the close handshake
fails.

Modification:

If a close frame was already sent (or is still being sent) when a close
frame is received, don't echo another close frame (as required by
RFC 6455) but close the connection once our own close frame was written.
The force-close timeout still applies. Add tests for a server-initiated
close handshake, including the reproducer from the issue, and adjust
the simultaneous close test as no second close frame is written anymore.

Result:

Fixes #17776.
A server-initiated WebSocket close handshake completes correctly again.
This was referenced Oct 22, 2026
Fix server-initiated WebSocket close handshake failing with "promise already done" (#17983) #18032
Merged
Fix server-initiated WebSocket close handshake failing with "promise already done" (#17983) #18034
Merged
chrisvest added a commit that referenced this pull request Oct 22, 2026
@chrisvest
Fix server-initiated WebSocket close handshake failing with "promise …
21bad5d
…already done" (#17983) (#18034)

Motivation:

Since #17574, `WebSocketProtocolHandler.closeSent(promise)` cascades the
outcome of an already recorded close promise onto the new one. When the
server initiates the close handshake by writing a `CloseWebSocketFrame`
and the peer responds with its own close frame,
`WebSocketServerProtocolHandler.decode()` creates a new promise, passes
it to `closeSent()` and then to `WebSocketServerHandshaker.close()`. As
our own close frame was already written, the new promise is completed
immediately, so the write in `close()` fails with
`IllegalArgumentException: promise already done` and the close handshake
fails.

Modification:

If a close frame was already sent (or is still being sent) when a close
frame is received, don't echo another close frame (as required by RFC
6455) but close the connection once our own close frame was written. The
force-close timeout still applies. Add tests for a server-initiated
close handshake, including the reproducer from the issue, and adjust the
simultaneous close test as no second close frame is written anymore.

Result:

Fixes #17776. A server-initiated
WebSocket close handshake completes correctly again.

(cherry picked from commit 7a6f630)
chrisvest added a commit that referenced this pull request Oct 22, 2026
@chrisvest
Fix server-initiated WebSocket close handshake failing with "promise …
d3afde1
…already done" (#17983) (#18032)

Motivation:

Since #17574, `WebSocketProtocolHandler.closeSent(promise)` cascades the
outcome of an already recorded close promise onto the new one. When the
server initiates the close handshake by writing a `CloseWebSocketFrame`
and the peer responds with its own close frame,
`WebSocketServerProtocolHandler.decode()` creates a new promise, passes
it to `closeSent()` and then to `WebSocketServerHandshaker.close()`. As
our own close frame was already written, the new promise is completed
immediately, so the write in `close()` fails with
`IllegalArgumentException: promise already done` and the close handshake
fails.

Modification:

If a close frame was already sent (or is still being sent) when a close
frame is received, don't echo another close frame (as required by RFC
6455) but close the connection once our own close frame was written. The
force-close timeout still applies. Add tests for a server-initiated
close handshake, including the reproducer from the issue, and adjust the
simultaneous close test as no second close frame is written anymore.

Result:

Fixes #17776. A server-initiated
WebSocket close handshake completes correctly again.

(cherry picked from commit 7a6f630)
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@normanmaurer @lltopk
Port 4.1: Arm force-close timeout when an inbound CLOSE frame is echo…
3887773
…ed (netty#17574) (netty#17710)

Motivation:

WebSocketServerProtocolHandler.decode() writes the CLOSE echo directly
via WebSocketServerHandshaker.close(), bypassing this handler's own
write()/close() overrides where forceCloseTimeoutMillis was armed. If
the peer stops draining its socket, the echo write never completes and
the channel, its file descriptor and buffers are pinned forever.

Modifications:

Arm the timeout explicitly after the echo write is issued, and also
from a new flush() override so a bare write(CloseWebSocketFrame) not
followed by close() gets the same protection. The timeout is applied
after the write/flush attempt, not before, so a write that completes
synchronously never races the deadline.

Result:

Awalys close the channel even when the remote peer stops reading
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@chrisvest @lltopk
Fix server-initiated WebSocket close handshake failing with "promise …
5b20ef9
…already done" (netty#17983) (netty#18032)

Motivation:

Since netty#17574, `WebSocketProtocolHandler.closeSent(promise)` cascades the
outcome of an already recorded close promise onto the new one. When the
server initiates the close handshake by writing a `CloseWebSocketFrame`
and the peer responds with its own close frame,
`WebSocketServerProtocolHandler.decode()` creates a new promise, passes
it to `closeSent()` and then to `WebSocketServerHandshaker.close()`. As
our own close frame was already written, the new promise is completed
immediately, so the write in `close()` fails with
`IllegalArgumentException: promise already done` and the close handshake
fails.

Modification:

If a close frame was already sent (or is still being sent) when a close
frame is received, don't echo another close frame (as required by RFC
6455) but close the connection once our own close frame was written. The
force-close timeout still applies. Add tests for a server-initiated
close handshake, including the reproducer from the issue, and adjust the
simultaneous close test as no second close frame is written anymore.

Result:

Fixes netty#17776. A server-initiated
WebSocket close handshake completes correctly again.

(cherry picked from commit 7a6f630)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
@yawkat yawkat Awaiting requested review from yawkat

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.19.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@normanmaurer @xhae123 @netty-project-bot @chrisvest
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.