summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@chromium.org>2024-10-23 23:15:12 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-10-24 16:58:17 +0000
commitae384f8623aeb36809541a5e07900a77a0960d5f (patch)
tree4df7deefd42150f8d171b54bdcb06b539c983ffa
parent70a4e643e66af182709f0888d7727f54fb6b7ea9 (diff)
downloadgit-repo-ae384f8623aeb36809541a5e07900a77a0960d5f.tar.gz
[event_log] Stop leaking semaphore resources
With the global state and fork, we are left with uncleaned resources. Isolate mulitprocessing.Value in a function so we stop the leak. Bug: 353656374 Change-Id: If50bb544bda12b72f00c02bc1d2c0d19de000b88 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/440261 Commit-Queue: Josip Sokcevic <sokcevic@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Josip Sokcevic <sokcevic@google.com>
-rw-r--r--event_log.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/event_log.py b/event_log.py
index ef01394a..9ef52247 100644
--- a/event_log.py
+++ b/event_log.py
@@ -168,8 +168,10 @@ class EventLog:
168 f.write("\n") 168 f.write("\n")
169 169
170 170
171# An integer id that is unique across this invocation of the program. 171# An integer id that is unique across this invocation of the program, to be set
172_EVENT_ID = multiprocessing.Value("i", 1) 172# by the first Add event. We can't set it here since it results in leaked
173# resources (see: https://issues.gerritcodereview.com/353656374).
174_EVENT_ID = None
173 175
174 176
175def _NextEventId(): 177def _NextEventId():
@@ -178,6 +180,12 @@ def _NextEventId():
178 Returns: 180 Returns:
179 A unique, to this invocation of the program, integer id. 181 A unique, to this invocation of the program, integer id.
180 """ 182 """
183 global _EVENT_ID
184 if _EVENT_ID is None:
185 # There is a small chance of race condition - two parallel processes
186 # setting up _EVENT_ID. However, we expect TASK_COMMAND to happen before
187 # mp kicks in.
188 _EVENT_ID = multiprocessing.Value("i", 1)
181 with _EVENT_ID.get_lock(): 189 with _EVENT_ID.get_lock():
182 val = _EVENT_ID.value 190 val = _EVENT_ID.value
183 _EVENT_ID.value += 1 191 _EVENT_ID.value += 1