Skip to content

Commit ae384f8

Browse files
sokcevicGLUCI
authored andcommitted
[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 <[email protected]> Reviewed-by: Gavin Mak <[email protected]> Tested-by: Josip Sokcevic <[email protected]>
1 parent 70a4e64 commit ae384f8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

event_log.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ def Write(self, filename):
168168
f.write("\n")
169169

170170

171-
# An integer id that is unique across this invocation of the program.
172-
_EVENT_ID = multiprocessing.Value("i", 1)
171+
# An integer id that is unique across this invocation of the program, to be set
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
173175

174176

175177
def _NextEventId():
@@ -178,6 +180,12 @@ def _NextEventId():
178180
Returns:
179181
A unique, to this invocation of the program, integer id.
180182
"""
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)
181189
with _EVENT_ID.get_lock():
182190
val = _EVENT_ID.value
183191
_EVENT_ID.value += 1

0 commit comments

Comments
 (0)