Skip to content

Commit

Permalink
Fix UDS failing if socket already exists
Browse files Browse the repository at this point in the history
In trying to use UDS in the Datadog injector test suite, I discovered
that the UDS socket functionality doesn't work particularly well in
containers. I suspect this is due to the atexit hook not being called
due to the abrupt container shutdown process. Subsequent runs of the
container will then fail as the file already exists and results in a
`OSError: [Errno 98] Address already in use` exception.
  • Loading branch information
Kyle-Verhoog committed Feb 16, 2024
1 parent 55ac583 commit 80c9ec7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ddapm_test_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,10 @@ def main(args: Optional[List[str]] = None) -> None:

apm_sock: Optional[socket.socket] = None
if parsed_args.trace_uds_socket is not None:
if os.path.exists(parsed_args.trace_uds_socket):
os.unlink(parsed_args.trace_uds_socket)
apm_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
apm_sock.bind(parsed_args.trace_uds_socket)
os.chmod(parsed_args.trace_uds_socket, 0o722)
atexit.register(lambda: os.unlink(parsed_args.trace_uds_socket))

if parsed_args.trace_request_delay is not None:
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/uds-c99ea5d099e67156.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Remove any existing UDS socket. If a socket was left behind by a previous
instance of the test agent then it would fail to start.

0 comments on commit 80c9ec7

Please sign in to comment.