Skip to content

Commit

Permalink
Fix ClassCastException in HttpOperations#initShortId() (#3542)
Browse files Browse the repository at this point in the history
Calling `HttpOperations#initShortId()` could cause a
`ClassCastException` if the underlying connection was replaced between
checking its type and casting it to `AtomicLong`, for example if
`ChannelOperations#terminate()` was called on another thread.

See also:
https://github.com/reactor/reactor-netty/blob/667f8c9cbf5a227a15f6d0a2f3aab7c4777613da/reactor-netty-core/src/main/java/reactor/netty/channel/ChannelOperations.java#L515

Fixes #3541

Co-authored-by: Violeta Georgieva <[email protected]>
  • Loading branch information
joschi and violetagg committed Dec 11, 2024
1 parent 5a8a02c commit 8d22dec
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ protected final boolean markSentHeaderAndBody(Object... objectsToRelease) {

@Override
protected final String initShortId() {
if (connection() instanceof AtomicLong) {
return channel().id().asShortText() + '-' + ((AtomicLong) connection()).incrementAndGet();
Connection connection = connection();
if (connection instanceof AtomicLong) {
return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).incrementAndGet();
}
return super.initShortId();
}
Expand Down

0 comments on commit 8d22dec

Please sign in to comment.