Skip to content

fix(undertow): resolve buffer already freed exception during shutdown#3919

Merged
jknack merged 1 commit intomainfrom
3918
Apr 21, 2026
Merged

fix(undertow): resolve buffer already freed exception during shutdown#3919
jknack merged 1 commit intomainfrom
3918

Conversation

@jknack
Copy link
Copy Markdown
Member

@jknack jknack commented Apr 21, 2026

Fixes an IllegalStateException: UT000091: Buffer has already been freed that occurs during server teardown in gRPC tests.

When raw request or response channels are acquired, Undertow shifts the exchange lifecycle management to the channels. Explicitly invoking exchange.endExchange() prematurely frees the pooled ByteBuffers. During server shutdown, the HTTP/2 FrameCloseListener attempts to gracefully close the connection and release the same buffers, resulting in a race condition and the subsequent exception.

Removed explicit exchange.endExchange() calls when streams are active in UndertowGrpcExchange and UndertowGrpcInputBridge. Replaced them with XNIO's IoUtils.safeClose(channel), allowing Undertow's internal state machine to naturally flush, close, and terminate the exchange.

Fixes an `IllegalStateException: UT000091: Buffer has already been freed` that occurs during server teardown in gRPC tests.

When raw request or response channels are acquired, Undertow shifts the exchange lifecycle management to the channels. Explicitly invoking `exchange.endExchange()` prematurely frees the pooled ByteBuffers. During server shutdown, the HTTP/2 `FrameCloseListener` attempts to gracefully close the connection and release the same buffers, resulting in a race condition and the subsequent exception.

Removed explicit `exchange.endExchange()` calls when streams are active in `UndertowGrpcExchange` and `UndertowGrpcInputBridge`. Replaced them with XNIO's `IoUtils.safeClose(channel)`, allowing Undertow's internal state machine to naturally flush, close, and terminate the exchange.
@jknack jknack added this to the 4.5.0 milestone Apr 21, 2026
@jknack jknack merged commit b9cd684 into main Apr 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant