-
Notifications
You must be signed in to change notification settings - Fork 141
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
Not all logs are captured when a container is dropped #719
Comments
Beyond waiting for the log streams to finish, we may want to first request that Docker stop the container, and then only delete the container after waiting for log streams. Currently, dropping the container requests deletion right away, and I think there may be a race between log streams ending due to container deletion versus log streams ending due to the process exiting. |
Hi there 👋 This is actually a good question. Since we allow custom consumers, this can result in significant delays per drop (for example, many nested consumers). Perhaps, an explicit interface to enforce the behavior instead (e.g However, the important part is that this behavior is likely desirable in most cases. Thus, I think it’s reasonable to have them joined/awaited on drop. Mentioning that custom implementation of the trait may affect |
That's a good point too. In general, it also depends on the container. Usually, there is graceful shutdown logic and default timeouts should cover that. But we can request stop prior to deletion just to ensure container's stopped. |
When a container is created with a LogConsumer, the ContainerAsync does not wait for the logs to stop while dropping. If the process ends quickly, e.g. when running a single
cargo test
, some logs may not be captured by the time the process ends.See this example failing test. Note that by its nature it's a flaky test, so you may need to increase the
$(seq 20)
argument to reproduce it, though on my relatively fast machine the counter never gets past 1 or 2.I'm able to workaround this by wrapping the container and avoiding using LogConsumer at all:
But that's unfortunate. I think if someone is using a LogConsumer they'd prefer that all logs are captured.
I think the problem is that the log consumer task is created with
tokio::spawn
, and the corresponding handle is never joined. https://github.com/testcontainers/testcontainers-rs/blob/main/testcontainers/src/core/containers/async_container.rs#L71.I'm more than happy to fix this myself, but wanted to gauge maintainer interest first, since adding more blocking calls to a
Drop
is generally unpleasant.The text was updated successfully, but these errors were encountered: