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

fix NPE and other exceptions thrown when work fails to process before work execution #32566

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

m-trieu
Copy link
Contributor

@m-trieu m-trieu commented Sep 25, 2024

StreamingModeExecutionContext requires a call to start() in order to work correctly.
If an exception is thrown during work execution before a call to start(), its possible that internal StreamingModeExecutionContext members are null.

Fix NPE in calls to invalidateCache() made w/o a call to start().
Also prevent ComputationWorkExecutor.invalidate() from crashing the worker.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@m-trieu
Copy link
Contributor Author

m-trieu commented Sep 25, 2024

R: @arunpandianp

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

}

public Windmill.WorkItem getWorkItem() {
return work.getWorkItem();
return checkNotNull(work).getWorkItem();
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just leave it as work.getWorkItem, NullpointerException is clearer than IllegalArgumentException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checker will complain since we mark work field as Nullable now

this will still throw an NPE with the checkNotNull check

i added a more clear error message.

try {
context().invalidateCache();
Copy link
Contributor

Choose a reason for hiding this comment

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

lets keep it outside and not suppress the exception. I'm not sure about the implications of suppressing the exception here, it is better to fail than operating in an inconsistent state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed over chat.
Safe because:

  • logic on invalidate cache will not run if work is null
  • Only 1 thread holds a reference to ComputationWorkExecutor and the only way it can be reused by another thread is if it is released to ComputationState. If an exception is thrown during processing, the ComputationWorkExecutor will not be reused and the reference freed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either is okay here, since even if we throw it the upper layer suppresses it. But in general it is better to not suppress unexpected exceptions and let the upper layer handle or re-throw it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@m-trieu
Copy link
Contributor Author

m-trieu commented Sep 26, 2024

@scwhittle ready for merge thank you!

@scwhittle
Copy link
Contributor

Precommit failure is pubsub auth issue, seems unrelated.

@scwhittle scwhittle merged commit aabae27 into apache:master Sep 26, 2024
16 of 17 checks passed
Naireen pushed a commit to Naireen/beam that referenced this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants