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

Detect issue with LTTng and Docker and report error when tracing #66

Conversation

christophebedard
Copy link
Member

@christophebedard christophebedard commented Apr 20, 2023

There is an issue with LTTng when using more than one Docker container that share the same mounted home directory. When trying to trace in a second container, LTTng will mistakenly think that there is a session daemon running, so it will happily trace, but no trace data will be recorded, because there isn't actually a session daemon in that container. The fix is to use a different LTTng home, e.g., by setting the LTTNG_HOME environment variable to a unique value. See this LTTng issue: https://bugs.lttng.org/issues/1371

This PR detects this (very small) corner case and reports the issue to the user so that they can set LTTNG_HOME. Example:

  1. Tracing works fine in the first container:
container1$ ros2 trace -s my-sesh-container1
UST tracing enabled (59 events)
kernel tracing disabled
context (3 fields)
writing tracing session to: /home/user/.ros/tracing/my-sesh-container1
press enter to start...
press enter to stop...
stopping & destroying tracing session
  1. But an error will be reported in the second container:
container2$ ros2 trace -s my-sesh-container2
UST tracing enabled (59 events)
kernel tracing disabled
context (3 fields)
writing tracing session to: /home/user/.ros/tracing/my-sesh-container2
press enter to start...
error: lttng-sessiond seems to exist, but is unreachable. If using two containers with the same HOME directory, set the LTTNG_HOME environment variable to a unique value for each container. See: https://bugs.lttng.org/issues/1371
  1. Setting LTTNG_HOME to a unique value (so that container 2 has its own LTTng home) and tracing again will work:
container2$ export LTTNG_HOME="$HOME/.lttng_home2"
container2$ ros2 trace -s my-sesh-container2
UST tracing enabled (59 events)
kernel tracing disabled
context (3 fields)
writing tracing session to: /home/user/.ros/tracing/my-sesh-container2
press enter to start...
press enter to stop...
stopping & destroying tracing session

Note that we must first try to spawn a session daemon is there isn't one, because, when a Docker container is killed/stopped, the ~/.lttng/lttng-sessiond.pid file (which contains the PID of the session daemon that is expected to be running) still exists. This would result in a false positive due to the way we detect cases of the Docker issue. If we manage to spawn a session daemon before checking for an unreachable session daemon, then we avoid the false positive.

Also, note that the LTTNG_HOME directory must exist; LTTng will not create it. Therefore, make sure to tell the user to create the directory.

Signed-off-by: Christophe Bedard christophe.bedard@apex.ai

@christophebedard christophebedard self-assigned this Apr 20, 2023
@christophebedard christophebedard force-pushed the christophebedard/detect-lttng-docker-issue-when-tracing branch 3 times, most recently from 470cb4b to 7712655 Compare April 21, 2023 00:11
Signed-off-by: Christophe Bedard <christophe.bedard@apex.ai>
@christophebedard christophebedard force-pushed the christophebedard/detect-lttng-docker-issue-when-tracing branch from 7712655 to 4a360b0 Compare May 1, 2023 18:46
@christophebedard christophebedard marked this pull request as ready for review May 2, 2023 22:50
Copy link
Member

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

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

A small corner case, but worth covering as Docker is pretty popular in our community.

@christophebedard
Copy link
Member Author

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@christophebedard christophebedard merged commit 00df8fe into rolling May 3, 2023
@christophebedard christophebedard deleted the christophebedard/detect-lttng-docker-issue-when-tracing branch May 3, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants