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

Prevent duplicate attempts to start Ryuk container #2245

Merged
merged 5 commits into from Jan 19, 2020

Conversation

rnorth
Copy link
Member

@rnorth rnorth commented Jan 13, 2020

If for example, checks fail once but the Docker client is otherwise initialized, an error would occur due to an attempt to start a Ryuk container twice with the same name.
This changed is aimed at avoiding that situation.

Additionally, if checks fail once they should fail on every subsequent attempt to start a client. Therefore, we cache the failure and rethrow it.

@@ -17,9 +17,6 @@
import lombok.SneakyThrows;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.rnorth.visibleassertions.VisibleAssertions;
Copy link
Member Author

Choose a reason for hiding this comment

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

Using VisibleAssertions for the logging in checks seems like major overkill, so I've changed it to use simple log statements.

Comment on lines 152 to 161
// fail-fast if checks have failed previously
if (cachedChecksFailure != null) {
throw cachedChecksFailure;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

It seems like a bug that currently checks can fail one time and then even try to run the checks again. We shouldn't; we should be forcing a failure so that the check failure gets investigated (rather than just the first test failing).

}
);
}
} catch (RuntimeException e) {
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about catching any Exception, not just RuntimeException?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, unless there's a naughty @SneakyThrows somewhere, it doesn't look like any checked exceptions are thrown. Also, if we catch an Exception we're in a situation where the client() method would have to be able to thow Exception. We could wrap a cached Exception inside a RuntimeException. But this feels a bit excessive.

Copy link
Member

@bsideup bsideup Jan 13, 2020

Choose a reason for hiding this comment

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

I am just cautious about the future changes where we may introduce a checked exception that is thrown but not stored to be re-thrown later

Copy link
Member

Choose a reason for hiding this comment

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

@SneakyThrows is another good point, yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps the good news is that a newly thrown checked exception would force us to catch it (client doesn't declare throws) - unless we use @SneakyThrows a lot more, which I think we should try and avoid. 😀

If for example, checks fail once but the Docker client is otherwise initialized, an error would occur due to an attempt to start a Ryuk container twice with the same name.
This changed is aimed at avoiding that situation.

Additionally, if checks fail once they should fail on every subsequent attempt to start a client. Therefore, we cache the failure and rethrow it.
@rnorth rnorth added this to the next milestone Jan 18, 2020
@bsideup bsideup merged commit fb869c0 into master Jan 19, 2020
@delete-merged-branch delete-merged-branch bot deleted the prevent-ryuk-double-start branch January 19, 2020 13:04
quincy pushed a commit to quincy/testcontainers-java that referenced this pull request May 28, 2020
Prevent duplicate attempts to start Ryuk container
If for example, checks fail once but the Docker client is otherwise initialized, an error would occur due to an attempt to start a Ryuk container twice with the same name.
This changed is aimed at avoiding that situation.

Additionally, if checks fail once they should fail on every subsequent attempt to start a client. Therefore, we cache the failure and rethrow it.


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

2 participants