GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix promise lost in ClientSide AuthHandler by hangc0276 · Pull Request #3902 · apache/bookkeeper

Conversation

@hangc0276

@hangc0276 hangc0276 commented Apr 2, 2023

Copy link
Copy Markdown
Contributor

Motivation

#3783 changed the AddEntry Request type from BookieProtocol.AddRequest to ByteBuf or ByteBufList, leading to the AddEntry request being added into waitingForAuth queue in the client-side AuthHandler

bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java

Lines 787 to 791 in 0171a40

if (toSend instanceof ByteBuf) {
request = ((ByteBuf) toSend).retainedDuplicate();
} else {
request = ByteBufList.clone((ByteBufList) toSend);
}

bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/AuthHandler.java

Lines 363 to 364 in 0171a40

} else if (msg instanceof ByteBuf || msg instanceof ByteBufList) {
waitingForAuth.add(msg);

For the requests in the waitingForAuth, they will be polled out by AuthHandshakeCompleteCallback#operationComplete.

bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/AuthHandler.java

Lines 426 to 436 in 0171a40

public void operationComplete(int rc, Void v) {
if (rc == BKException.Code.OK) {
synchronized (this) {
authenticated = true;
Object msg = waitingForAuth.poll();
while (msg != null) {
ctx.writeAndFlush(msg);
msg = waitingForAuth.poll();
}
}
} else {

However, the waitingForAuth queue only stores the AddEntry request, and it ignores the related ChannelPromise. When polling requests from the waitingForAuth queue in AuthHandshakeCompleteCallback#operationComplete, those requests will be written and flushed into the Netty channel without passing any ChannelPromises, and Netty will use voidPromise by default.

In a word, the AddEntry request side passed ChannelPromise will be replaced with voidPromise, and the original promise will never be complete and the following operations won't execute.

bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java

Lines 1159 to 1169 in 0171a40

ChannelPromise promise = channel.newPromise().addListener(future -> {
if (future.isSuccess()) {
nettyOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
CompletionValue completion = completionObjects.get(key);
if (completion != null) {
completion.setOutstanding();
}
} else {
nettyOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
}
});

There are two impactions:

  • The nettyOpLogger metric won't update
  • The addEntryOutstanding counter metric won't update

Changes

Store the ChannelPromise along with the request in the client-side AuthHandle and pass it to the Netty channel when polling out.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hangc0276
Fix promise lost in ClientSide AuthHandler
b09ce8a
@hangc0276
hangc0276 requested review from dlg99, eolivelli, merlimat and zymap April 2, 2023 15:37
@hangc0276 hangc0276 self-assigned this Apr 2, 2023
@hangc0276 hangc0276 added type/bug area/bookie release/4.14.8 release/4.15.5 release/4.16.1 labels Apr 2, 2023
@hangc0276 hangc0276 added this to the 4.17.0 milestone Apr 2, 2023
zymap
zymap approved these changes Apr 3, 2023
View reviewed changes

@zymap zymap left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have a test?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
horizonzy
horizonzy approved these changes Apr 6, 2023
View reviewed changes

@horizonzy horizonzy left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
dlg99
dlg99 reviewed Apr 10, 2023
View reviewed changes

@dlg99 dlg99 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hangc0276 hangc0276 added release/4.16.2 and removed release/4.16.1 labels Apr 14, 2023
wenbingshen
wenbingshen approved these changes May 19, 2023
View reviewed changes

@wenbingshen wenbingshen left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Catch!

It doesn't seem very easy to add an AddEntry request before the auth handshake is complete, especially getting it into the waitingForAuth queue, and the auth request will also trigger the promise execution.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zymap zymap added release/4.16.3 and removed release/4.16.2 labels Jun 19, 2023
@hangc0276 hangc0276 removed release/4.14.8 release/4.15.5 labels Jun 25, 2023
@zymap zymap added release/4.16.4 and removed release/4.16.3 labels Aug 29, 2023
@hangc0276

hangc0276 commented Jan 8, 2024

Copy link
Copy Markdown
Contributor Author

We need to add a unit test for this change, move to the next release

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hangc0276 hangc0276 added release/4.16.5 and removed release/4.16.4 labels Jan 8, 2024
@nicoloboschi nicoloboschi removed the release/4.16.5 label Mar 21, 2024
@eolivelli eolivelli removed this from the 4.17.0 milestone May 3, 2024
@hezhangjian hezhangjian mentioned this pull request May 23, 2024
fix: reference counting (retain/release) in PerChannelBookieClient #4293
Merged
@hezhangjian

hezhangjian commented May 24, 2024

Copy link
Copy Markdown
Member

As dicussed in #4293 I think we can close this PR now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hezhangjian hezhangjian closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dlg99 dlg99 dlg99 left review comments
@zymap zymap zymap approved these changes
@wenbingshen wenbingshen wenbingshen approved these changes
@merlimat merlimat Awaiting requested review from merlimat
@eolivelli eolivelli Awaiting requested review from eolivelli
+1 more reviewer
@horizonzy horizonzy horizonzy approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@hangc0276 hangc0276

Labels

area/bookie type/bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@hangc0276 @hezhangjian @dlg99 @horizonzy @zymap @wenbingshen @eolivelli @nicoloboschi
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.