Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Avoid a race condition in RetryingExecutorService #278

Merged
merged 1 commit into from
May 18, 2018

Conversation

drigz
Copy link
Member

@drigz drigz commented May 17, 2018

This fixes #274, which occurs when the task completes before the
Future is added to the callables map (because the corresponding
submit() is still executing). In that case, callable is null, which
causes latches.get(callable) to throw an NPE.

The bug can be reproduced with the added test by adding
Thread.sleep(1000) below the completionService.submit call.

This fixes rosjava#274, which occurs when the task completes before the
`Future` is added to the `callables` map (because the corresponding
submit() is still executing). In that case, `callable` is null, which
causes latches.get(callable) to throw an NPE.

The bug can be reproduced with the added test by adding
`Thread.sleep(1000)` below the `completionService.submit` call.
@drigz drigz requested a review from jubeira May 17, 2018 15:53
@drigz
Copy link
Member Author

drigz commented May 18, 2018

If you prefer I can remove the test from this PR - it's pretty messy since it uses a real ScheduledThreadPoolExecutor and lots of timeouts. I looked into faking ScheduledExecutorService but it's not trivial. You can see the scale in google-cloud-java's FakeScheduledExecutorService (I haven't looked in to reusing that).

Copy link

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

The fix makes sense to me, and I think it's perfectly fine to add the test in the same PR.

@msmcconnell perhaps you will want to try this out :)

@drigz drigz merged commit f2134b2 into rosjava:kinetic May 18, 2018
@drigz
Copy link
Member Author

drigz commented May 18, 2018

Thanks for the review!

@msmcconnell
Copy link

Nice job drigz! I had locally confirmed the same cause of the issue and a similar solution (didn't have time to update it here). Now I should be able to re-target back to the main kinetic branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Future key returns null for ConcurrentHashMap
4 participants