Skip to content

Commit

Permalink
Fix a deadlock
Browse files Browse the repository at this point in the history
close_socket acquires _socket_lock, and calling it with the lock held
deadlocks.

On top of this the warning did not prove very useful, as it would also
trigger when the application is sending metrics from another thread
when the process forks, in which case the warning is a bit misleading.

Without the warning there is no reason to check for socket being open,
so just silently call close_socket() after the fork to avoid sharing
the file descriptor between processes if another thread re-opened it
between pre_fork() and fork itself.
  • Loading branch information
vickenty committed Mar 5, 2024
1 parent 4dcf1ed commit 1b88100
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions datadog/dogstatsd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,10 +1370,7 @@ def post_fork(self):

log.debug("[%d] post_fork for %s", os.getpid(), self)

with self._socket_lock:
if self.socket or self.telemetry_socket:
log.warning("Open socket detected after fork. Call pre_fork() before os.fork().")
self.close_socket()
self.close_socket()

self._forking = False

Expand Down

0 comments on commit 1b88100

Please sign in to comment.