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 — fix: reference counting (retain/release) in PerChannelBookieClient by lhotari · Pull Request #4293 · apache/bookkeeper Conversation
|
|
@hangc0276 @poorbarcode Please review. This addresses the remaining gaps of #4289. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@hangc0276 @poorbarcode @codelipenghui @BewareMyPower @merlimat Please review. This addresses the remaining gaps of #4289. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a small comment
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
77b09c2 to
74f9782
Compare
|
I finally found the root cause in Bookkeeper client. The client had several buffer leaks since the ByteBufList lifecycle was incorrectly handled and write promises were dropped and ignored when authentication was in progress. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Can we close #3902 after this pr is merged? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ChannelPromise promise; | ||
| // check if the message has an associated promise as the next element in the queue | ||
| if (waitingForAuth.peek() instanceof ChannelPromise) { | ||
| promise = (ChannelPromise) waitingForAuth.poll(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If found this issue before https://github.com/apache/bookkeeper/pull/3902/files. Your solution is better.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| body = UnsafeByteOperations.unsafeWrap(toSend.toArray()); | ||
| } | ||
| ByteString body = ByteStringUtil.byteBufListToByteString(toSend); | ||
| toSend.retain(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The toSend already convert to ByteString, why do we need to retain and release after flushed no matter the flush succeed or not?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The ByteString doesn't handle the lifecycle of the buffers referenced by the ByteString.
It's the toSend.retain() which handles the lifecycle.
The cleanupActionFailedBeforeWrite and cleanupActionAfterWrite parameters (Runnables) are used to ensure that the reference count is properly decreased later.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We already converted toSend to ByteString, the lifecycle of toSend can be tracked by the caller of the method.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
| ByteString body = ByteStringUtil.byteBufListToByteString(bufToSend); | ||
| bufToSend.retain(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do not need retain the bufToSend?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
same answer as #4293 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nice catch! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…4293) ### Motivation This addresses the remaining gaps of #4289 in handling ByteBuf retain/release. This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: #791 (comment) . This PR fixes several problems: * ByteString buffer lifecycle in client, follows ByteBufList lifecycle * ByteBufList lifecycle, moved to write promise * Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises. ### Changes - add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite - use these callback actions for proper cleanup - extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString - properly handle releasing of ByteBufList in the write promise - properly handle calling promises that are buffered while authentication is in progress (cherry picked from commit 0ef2f99)
| ChannelPromise compositePromise = ctx.newPromise(); | ||
| compositePromise.addListener(future -> { | ||
| // release the ByteBufList after the write operation is completed | ||
| ReferenceCountUtil.safeRelease(b); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Use ReferenceCountUtil.relesse(b) to expose potential exceptions in release the ByteBufList?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…pache#4293) This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release. This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) . This PR fixes several problems: * ByteString buffer lifecycle in client, follows ByteBufList lifecycle * ByteBufList lifecycle, moved to write promise * Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises. - add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite - use these callback actions for proper cleanup - extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString - properly handle releasing of ByteBufList in the write promise - properly handle calling promises that are buffered while authentication is in progress
…pache#4293) ### Motivation This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release. This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) . This PR fixes several problems: * ByteString buffer lifecycle in client, follows ByteBufList lifecycle * ByteBufList lifecycle, moved to write promise * Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises. ### Changes - add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite - use these callback actions for proper cleanup - extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString - properly handle releasing of ByteBufList in the write promise - properly handle calling promises that are buffered while authentication is in progress (cherry picked from commit 0ef2f99) # Conflicts: # bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
…4293) (#4396) ### Motivation This addresses the remaining gaps of #4289 in handling ByteBuf retain/release. This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: #791 (comment) . This PR fixes several problems: * ByteString buffer lifecycle in client, follows ByteBufList lifecycle * ByteBufList lifecycle, moved to write promise * Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises. ### Changes - add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite - use these callback actions for proper cleanup - extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString - properly handle releasing of ByteBufList in the write promise - properly handle calling promises that are buffered while authentication is in progress (cherry picked from commit 0ef2f99) # Conflicts: # bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
…pache#4293) ### Motivation This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release. This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) . This PR fixes several problems: * ByteString buffer lifecycle in client, follows ByteBufList lifecycle * ByteBufList lifecycle, moved to write promise * Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises. ### Changes - add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite - use these callback actions for proper cleanup - extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString - properly handle releasing of ByteBufList in the write promise - properly handle calling promises that are buffered while authentication is in progress
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.