From e5fb6e585f593162ee2b10ad64cdd7ea2a577a06 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Tue, 19 Dec 2023 09:45:44 -0800 Subject: [PATCH] git_trace2: Add socket timeout repo blocks indefinitely until trace collector receives trace events, which is not desired. This change adds a fixed timeout to connect and send operations. It is possible that some events will be lost. repo logs any failed trace operation. Bug: b/316227772 Change-Id: I017636421b8e22ae3fcbab9e4eb2bee1d4fbbff4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/398717 Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic Reviewed-by: Jason Chang --- git_trace2_event_log_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git_trace2_event_log_base.py b/git_trace2_event_log_base.py index f5424249..2f1aac76 100644 --- a/git_trace2_event_log_base.py +++ b/git_trace2_event_log_base.py @@ -38,6 +38,8 @@ import tempfile import threading +# Timeout when sending events via socket (applies to connect, send) +SOCK_TIMEOUT = 0.5 # in seconds # BaseEventLog __init__ Counter that is consistent within the same process p_init_count = 0 @@ -296,6 +298,7 @@ class BaseEventLog: with socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) as sock: + sock.settimeout(SOCK_TIMEOUT) sock.connect(path) self._WriteLog(sock.sendall) return f"af_unix:stream:{path}"