Skip to content

servlet: Ignore stream writes after the stream is closed - #13195

Merged
kannanjgithub merged 1 commit into
grpc:masterfrom
kannanjgithub:flake_frameAfterRstStreamShouldNotBreakClientChannel
Nov 23, 2026
Merged

kannanjgithub merged 1 commit into
grpc:masterfrom
kannanjgithub:flake_frameAfterRstStreamShouldNotBreakClientChannel

Conversation

@kannanjgithub

@kannanjgithub kannanjgithub commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Issue identified via flaky server transport test failures when run on Jetty.
AbstractTransportTest.frameAfterRstStreamShouldNotBreakClientChannel checks that a client which has reset a stream ignores HEADERS/DATA frames the server still sends on that stream (allowed by RFC 7540 section 5.1), and that the connection remains usable for new streams. The client writes a message and cancels the stream (RST_STREAM), and the server, without waiting, writes headers and a message on the same stream.

With the servlet server on Jetty this was flaky: the server-side writeHeaders() sometimes threw IllegalStateException("Committed") to the caller. When the client's RST_STREAM races ahead of the server's write, the container reports it via AsyncListener.onError on a container thread, which calls Sink.cancel() -> close() and completes the AsyncContext, committing the response. The application thread's writeHeaders() then calls setTrailerFields() on the committed response:

16.406 client sends RST_STREAM
16.565 Jetty thread: onError -> cancel() -> close()
-> writeTrailers(headersSent=false)
16.674 Jetty thread: asyncContext.complete() <- response committed
17.396 test thread: writeHeaders -> setTrailerFields
-> IllegalStateException("Committed")

Track in the Sink whether trailers have been written and make writeHeaders, writeFrame and writeTrailers no-ops afterwards, holding a lock so response mutations from the application and container threads are serialized. Writes after a cancel are thus silently dropped.

AbstractTransportTest.frameAfterRstStreamShouldNotBreakClientChannel
checks that a client which has reset a stream ignores HEADERS/DATA
frames the server still sends on that stream (allowed by RFC 7540
section 5.1), and that the connection remains usable for new streams.
The client writes a message and cancels the stream (RST_STREAM), and
the server, without waiting, writes headers and a message on the same
stream.

With the servlet server on Jetty this was flaky: the server-side
writeHeaders() sometimes threw IllegalStateException("Committed") to the
caller. When the client's RST_STREAM races ahead of the server's write,
the container reports it via AsyncListener.onError on a container
thread, which calls Sink.cancel() -> close() and completes the
AsyncContext, committing the response. The application thread's
writeHeaders() then calls setTrailerFields() on the committed response:

  16.406  client sends RST_STREAM
  16.565  Jetty thread: onError -> cancel() -> close()
                        -> writeTrailers(headersSent=false)
  16.674  Jetty thread: asyncContext.complete()  <- response committed
  17.396  test thread:  writeHeaders -> setTrailerFields
                        -> IllegalStateException("Committed")

Track in the Sink whether trailers have been written and make
writeHeaders, writeFrame and writeTrailers no-ops afterwards, holding a
lock so response mutations from the application and container threads
are serialized. Writes after a cancel are thus silently dropped, as with
the Netty server.

TAG=agy
CONV=367f1e32-a85a-4e2f-99f3-3ac0e3d14e20
@kannanjgithub
kannanjgithub merged commit 8b06439 into grpc:master Nov 23, 2026
23 of 25 checks passed
@kannanjgithub
kannanjgithub deleted the flake_frameAfterRstStreamShouldNotBreakClientChannel branch November 23, 2026 06:09
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.

3 participants