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

Protect NetworkImpl#close from concurrency issues #2203

Merged
merged 3 commits into from Apr 12, 2020
Merged

Protect NetworkImpl#close from concurrency issues #2203

merged 3 commits into from Apr 12, 2020

Conversation

pivovarit
Copy link
Contributor

@pivovarit pivovarit commented Dec 21, 2019

Since NetworkImpl#id is assigned lazily, close may not see the change and will fail with NPE.

@pivovarit pivovarit marked this pull request as ready for review December 21, 2019 09:49
@@ -52,17 +53,17 @@ static Network newNetwork() {
@Singular
private Set<Consumer<CreateNetworkCmd>> createNetworkCmdModifiers;

private String id;
private final AtomicReference<String> id = new AtomicReference<>();
Copy link
Member

Choose a reason for hiding this comment

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

  1. both getId and close are synchronized, the field can be volatile
  2. by making it final, you're breaking the backward compatibility, since (accidentally) the constructor was exposed to public (a class that was intended to be internal became private as it was defined in the interface), please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I thought that NetworkImpl is internal, but it indeed leaks out through the builder

Copy link
Member

Choose a reason for hiding this comment

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

FYI:
soon we will add japicmp to automate such checks

Copy link
Member

Choose a reason for hiding this comment

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

also, please do not unresolve other's comments.

@stale
Copy link

stale bot commented Mar 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@bsideup bsideup changed the title Ensure proper visibility of NetworkImpl#id value and exclude it from the builder Protect NetworkImpl#close from concurrency issues Apr 11, 2020
@bsideup bsideup added this to the next milestone Apr 11, 2020
@bsideup
Copy link
Member

bsideup commented Apr 11, 2020

@pivovarit I updated the PR and will merge it once CI is green :)

@bsideup bsideup merged commit cbd3220 into testcontainers:master Apr 12, 2020
@rnorth
Copy link
Member

rnorth commented Apr 13, 2020

This was released in https://github.com/testcontainers/testcontainers-java/releases/tag/1.14.0 🎉

Thanks for the contribution!

quincy pushed a commit to quincy/testcontainers-java that referenced this pull request May 28, 2020
)

* Increase thread safety of NetworkImpl

* un-volatile `id`

Co-authored-by: Sergei Egorov <bsideup@gmail.com>
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.

None yet

3 participants