-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
[Bug]: HealthStrategy tries to dereference a null Health pointer #801
Comments
Hi @massenz thanks for opening this issue. I think you are right, that double dereference should be checked. Would you mind sending a patch for it, hopefully adding a test for a nil health check? I can do it my self, but later this week 🙏 Thanks! |
Of course, I'd love to! Probably later in the day, or tomorrow at the latest. |
* [#801] Fix nil pointer dereference in HealthStrategy * Added another test to prove HealthStrategy fails for nil Health * Refactored error checking * Update wait/health_test.go Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> * Update wait/health_test.go Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> * Update wait/health_test.go Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> --------- Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
Thank you so much, @mdelapenya for jumping so quickly on this one and helping out. If there is any issue that you think you'd like me take a look at, I'd be happy to continue contributing |
My pleasure @massenz! Feel free to visit the issues, but I'm specially proud of the new example modules system. Would you like to contribute an example module for the technology you use the most? You can find docs here: https://golang.testcontainers.org/examples/ and a list of target modules here: #636 In any other case, contributions are always welcomed, be it in code, in docs, in tests... 🙏 |
Ah, last one tiny thing: it's |
Testcontainers version
0.17.0
Using the latest Testcontainers version?
Yes
Host OS
Ubuntu 22.04
Host arch
amd64
Go version
1.19
Docker version
Client: Docker Engine - Community Version: 23.0.0 API version: 1.42 Go version: go1.19.5 Git commit: e92dd87 Built: Wed Feb 1 17:47:51 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 23.0.0 API version: 1.42 (minimum version 1.12) Go version: go1.19.5 Git commit: d7573ab Built: Wed Feb 1 17:47:51 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.16 GitCommit: 31aa4358a36870b21a992d3ad2bef29e1d693bec runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0
Docker info
What happened?
I used the code exactly as in the docs (and other variations too) and the tests failed with a panic (see log):
Relevant log output
Additional information
This is caused by this line:
due to
Health
beingnil
(at least, initially) - however, the following should work (I've rewritten the strategy and tested to work, but it's been a very limited testing on just that one container):Whether this is "intended" I am not sure (but it achieves what I want, to wait for the container to be ready).
In any event, as a matter of best practice, before dereferencing "two levels deep" it would be better to defend against
nil
values.The text was updated successfully, but these errors were encountered: