Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-11282] Fix NPE in OpReadEntry #11292

Closed
wants to merge 1 commit into from

Conversation

Jason918
Copy link
Contributor

@Jason918 Jason918 commented Jul 13, 2021

Fixes #11282

Motivation

fix NPE in OpReadEntry, see issue #11282 .

Modifications

remove opReadEntry.readEntriesFailed in ManagedLedgerImpl::startReadOperationOnLedger, the state checking is handled by all the callers in OpReadEntry.

Verifying this change

  • Make sure that the change passes the CI checks.

Added new test case testManagedLedgerWithReadEntryWithoutNewerEntry.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • no-need-doc

bug fix.

Copy link

@littleorca littleorca left a comment

Choose a reason for hiding this comment

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

I think this won't work. When readEntriesFailed is called during initiate readPosition, the property readPosition was not assigned yet, and readEntriesFailed has a chance to call readPosition.getLedgerId(),which will cause another NPE.

Further more, I guess the callbacks should be concerned also.

@Jason918
Copy link
Contributor Author

I think this won't work. When readEntriesFailed is called during initiate readPosition, the property readPosition was not assigned yet, and readEntriesFailed has a chance to call readPosition.getLedgerId(),which will cause another NPE.

Further more, I guess the callbacks should be concerned also.

It's NoMoreEntriesToReadException in startReadOperationOnLedger right? So it's not running into the if branch for readPosition.getLedgerId().

And the callback is also assigned before the assignment of readPosition.

@Jason918
Copy link
Contributor Author

@littleorca After deep looking into this case, I found that more serious issue is that, when ManagedLedgerException.NoMoreEntriesToReadException occurs in OpReadEntry.create, this OpReadEntry object is actually recycled when create method finished. Any usage of this object would lead to some unexpected behavior.

@littleorca
Copy link

I think this won't work. When readEntriesFailed is called during initiate readPosition, the property readPosition was not assigned yet, and readEntriesFailed has a chance to call readPosition.getLedgerId(),which will cause another NPE.
Further more, I guess the callbacks should be concerned also.

It's NoMoreEntriesToReadException in startReadOperationOnLedger right? So it's not running into the if branch for readPosition.getLedgerId().

And the callback is also assigned before the assignment of readPosition.

Seems you are right. I've tried to reorder statements in create() method and ended up in failure, I probably messed up some details about the failure.

@codelipenghui codelipenghui added the type/bug The PR fixed a bug or issue reported a bug label Jul 22, 2021
@codelipenghui codelipenghui added this to the 2.9.0 milestone Jul 22, 2021
@lhotari
Copy link
Member

lhotari commented Aug 10, 2021

FYI, there are some thread safety issues in OpReadEntry . PR #11387 attempts to fix some of the thread safety issues.

@hangc0276
Copy link
Contributor

move to 2.8.2.

@lhotari
Copy link
Member

lhotari commented Sep 8, 2021

There seems to be an alternative approach to solve the NPE in PR #11813 . I currently prefer that change since it's fairly simple.

@Jason918
Copy link
Contributor Author

There seems to be an alternative approach to solve the NPE in PR #11813 . I currently prefer that change since it's fairly simple.

There maybe some race conditions in PR #11813, explained the details in that PR, PTAL. :)

@eolivelli eolivelli modified the milestones: 2.9.0, 2.10.0 Oct 6, 2021
@315157973
Copy link
Contributor

@lhotari @codelipenghui @hangc0276 PTAL

@github-actions
Copy link

@Jason918:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@Anonymitaet
Copy link
Member

@Jason918 seems this is a bug fix (no need to update docs)?

@Jason918
Copy link
Contributor Author

@Jason918 seems this is a bug fix (no need to update docs)?

Yes.

@github-actions
Copy link

@Jason918:Thanks for providing doc info!

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 24, 2021
@Jason918 Jason918 changed the title fix issue-11282 [Issue-11282] Fix NPE in OpReadEntry Nov 29, 2021
@Jason918
Copy link
Contributor Author

Close by duplication.

@Jason918 Jason918 closed this Jan 25, 2022
@michaeljmarshall michaeljmarshall removed this from the 2.10.0 milestone Feb 11, 2022
@michaeljmarshall
Copy link
Member

Removing release label and milestone since the PR is closed. Please re-add if we need to open the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE in OpReadEntry
9 participants