GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — Optimize wrap buffer cumulation in SslHandler and don't mutate input buffers by lhotari · Pull Request #14086 · netty/netty Conversation
|
|
@normanmaurer Thanks for the review. I applied your suggestions. PTAL |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I have been wondering the root cause of the problems in Apache Pulsar. I finally found the explanation how it's possible that SslHandler is able to corrupt buffers handled by Apache Pulsar. The issue #12919 is titled "ByteBuf slice duplicates are not slices". This behavior is very surprising. It explains why the SslHandler has been causing issues in Apache Pulsar. The incoming messages come from the network and use the LengthFieldBasedFrameDecoder, which slices the buffer into frame buffers. Pulsar later calls retainedDuplicate. This removes the effect of slicing (as described in issue #12919) and makes the buffer writable. The impact of this is that the original buffer used by the LengthFieldBasedFrameDecoder gets mutated by the SslHandler later when the sliced frame buffer (which is made writable with .retainedDuplicate) is passed to the Apache Bookkeeper client, which also uses Netty and contains an SslHandler. The SslHandler's cumulation in the attemptCopyToCumulation method thinks that it's fine to mutate the input buffer since it's writable and that's what causes data corruption. Issue #12919 references the vert.x issue eclipse-vertx/vert.x#4509. It seems vert.x applied a workaround in eclipse-vertx/vert.x#4517. I also found a workaround for a data corruption issue within Netty's http codecs, #11802. That was to address #11792. Such workarounds won't be needed when we eliminate the surprising behaviour. The PR will address it for Sslhandler and also optimise the cumulation. I think #12919 should also be addressed so that a duplicating a slice doesn't provide write access to the parent buffer outside of the slice. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@chrisvest @franz1981 do you also have a chance to review this PR? Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
As a followup, I also created #14093 with the title "Duplicate of slice should have the same capacity as the original slice so that it's not writable" to address the issue #12919 by @vietj, "ByteBuf slice duplicates are not slices". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…buffers (#14086) Motivation: SslHandler doesn't support sharing the input buffers since the input buffers get mutated. This issue has been reported as #14069. Fixes have already been made to support the use case using read-only buffers as input. However, this is not useful for existing Netty applications. I checked the Netty code once again and noticed that it's possible to optimize the current implementation in SslHandler and avoid the buffer mutation. The default behavior in SslHandler causes very hard to debug problems. In Pulsar, there have been issues open for multiple years that have been caused by the SslHandler's default behavior of mutating the input buffers (apache/pulsar#22601 is one starting point to the issues). The current implementation of SslHandler will mutate the input buffers by using the input buffer as a cumulation buffer when there's available capacity. This is not optimal at all. This PR contains an improvement where the cumulation buffer is allocated to the final size immediately so that cumulation is more optimal. That's why I think that this will be more optimal in the end and won't cause performance regressions. After these changes, it should be possible to pass a slice or duplicate of a buffer and the input buffer doesn't get mutated. The input buffer's readIndex will be modified so multiple threads cannot share the same input buffer without a slice or duplicate. I created a failing test case that shows that a duplicate buffer doesn't prevent input buffer mutation.  It's a very surprising behavior of SslHandler that passing a `.retainedDuplicate()` buffer could result in mutations to the original buffer. That's another reason why I think that SslHandler shouldn't ever mutate the inputs. Modification: - add `protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first, int bufferSize)` to AbstractCoalescingBufferQueue to support allocating an optimal cumulation buffer instead of using the input buffer as a cumulation buffer - remove dead code from `compose` where there was handling for CompositeByteBuf - `composeFirst` will be called before `compose` so this case isn't needed. Result: Fixes #14069 without the need to set the input buffer as read-only --------- Co-authored-by: Norman Maurer <[email protected]>
…4426) ### Motivation [Netty 4.1.111.Final](https://netty.io/news/2024/06/11/4-1-111-Final.html) contains important fixes: - netty/netty#14086 - netty/netty#14093 On the Pulsar side these address Broker stability when TLS with Bookkeeper V2 protocol is used between Broker and Bookies. The Bookkeeper client didn't contain a workaround for the Netty SslHandler "feature" like Pulsar did. That's why Bookkeeper client was impacted. Netty 4.1.111.Final will address those stability issues with the Bookkeeper client when using V2 protocol over TLS. ### Changes - Upgrade Netty to 4.1.111.Final - Switch to use grpc-netty-shaded instead of grpc-netty - grpc-java is not compatible with Netty 4.1.111.Final. [grpc-java supports only specific Netty versions](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty). The solution is to use grpc-netty-shaded instead of grpc-netty dependency. - Add module to shade jetcd-core partially so that it can work with grpc-netty-shaded. - jetcd-core library and it's transient dependency vertx-grpc has a direct dependency on grpc-netty and it doesn't work with grpc-netty-shaded without this solution. - this solution avoids the need to shade grpc libraries completely which would cause a lot of duplication and increase build times.
…4426) [Netty 4.1.111.Final](https://netty.io/news/2024/06/11/4-1-111-Final.html) contains important fixes: - netty/netty#14086 - netty/netty#14093 On the Pulsar side these address Broker stability when TLS with Bookkeeper V2 protocol is used between Broker and Bookies. The Bookkeeper client didn't contain a workaround for the Netty SslHandler "feature" like Pulsar did. That's why Bookkeeper client was impacted. Netty 4.1.111.Final will address those stability issues with the Bookkeeper client when using V2 protocol over TLS. - Upgrade Netty to 4.1.111.Final - Switch to use grpc-netty-shaded instead of grpc-netty - grpc-java is not compatible with Netty 4.1.111.Final. [grpc-java supports only specific Netty versions](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty). The solution is to use grpc-netty-shaded instead of grpc-netty dependency. - Add module to shade jetcd-core partially so that it can work with grpc-netty-shaded. - jetcd-core library and it's transient dependency vertx-grpc has a direct dependency on grpc-netty and it doesn't work with grpc-netty-shaded without this solution. - this solution avoids the need to shade grpc libraries completely which would cause a lot of duplication and increase build times. (cherry picked from commit a95f698)
…4426) [Netty 4.1.111.Final](https://netty.io/news/2024/06/11/4-1-111-Final.html) contains important fixes: - netty/netty#14086 - netty/netty#14093 On the Pulsar side these address Broker stability when TLS with Bookkeeper V2 protocol is used between Broker and Bookies. The Bookkeeper client didn't contain a workaround for the Netty SslHandler "feature" like Pulsar did. That's why Bookkeeper client was impacted. Netty 4.1.111.Final will address those stability issues with the Bookkeeper client when using V2 protocol over TLS. - Upgrade Netty to 4.1.111.Final - Switch to use grpc-netty-shaded instead of grpc-netty - grpc-java is not compatible with Netty 4.1.111.Final. [grpc-java supports only specific Netty versions](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty). The solution is to use grpc-netty-shaded instead of grpc-netty dependency. - Add module to shade jetcd-core partially so that it can work with grpc-netty-shaded. - jetcd-core library and it's transient dependency vertx-grpc has a direct dependency on grpc-netty and it doesn't work with grpc-netty-shaded without this solution. - this solution avoids the need to shade grpc libraries completely which would cause a lot of duplication and increase build times. (cherry picked from commit a95f698)
…pache#4426) ### Motivation [Netty 4.1.111.Final](https://netty.io/news/2024/06/11/4-1-111-Final.html) contains important fixes: - netty/netty#14086 - netty/netty#14093 On the Pulsar side these address Broker stability when TLS with Bookkeeper V2 protocol is used between Broker and Bookies. The Bookkeeper client didn't contain a workaround for the Netty SslHandler "feature" like Pulsar did. That's why Bookkeeper client was impacted. Netty 4.1.111.Final will address those stability issues with the Bookkeeper client when using V2 protocol over TLS. ### Changes - Upgrade Netty to 4.1.111.Final - Switch to use grpc-netty-shaded instead of grpc-netty - grpc-java is not compatible with Netty 4.1.111.Final. [grpc-java supports only specific Netty versions](https://github.com/grpc/grpc-java/blob/master/SECURITY.md#netty). The solution is to use grpc-netty-shaded instead of grpc-netty dependency. - Add module to shade jetcd-core partially so that it can work with grpc-netty-shaded. - jetcd-core library and it's transient dependency vertx-grpc has a direct dependency on grpc-netty and it doesn't work with grpc-netty-shaded without this solution. - this solution avoids the need to shade grpc libraries completely which would cause a lot of duplication and increase build times.
After Netty 4.1.111.Final, it's no longer necessary to make buffer copies when TLS is enabled. netty/netty#14086 contains the fix
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
SslHandler doesn't support a use case where the input ByteBuf is shared across multiple threads
There was an error while loading. Please reload this page.