Skip to content

Commit ab2d321

Browse files
kcwuLUCI
authored andcommitted
sync: fix connection error on macOS
With a large number of sync workers, the sync process may fail on macOS due to connection errors. The root cause is that multiple workers may attempt to connect to the multiprocessing manager server at the same time when handling the first job. This can lead to connection failures if there are too many pending connections, exceeding the socket listening backlog. Bug: 377538810 Change-Id: I1924d318d076ca3be61d75daa37bfa8d7dc23ed7 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/441541 Tested-by: Josip Sokcevic <[email protected]> Commit-Queue: Josip Sokcevic <[email protected]> Reviewed-by: Josip Sokcevic <[email protected]>
1 parent aada468 commit ab2d321

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

subcmds/sync.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,16 @@ def _GetSyncProgressMessage(self):
821821
jobs = jobs_str(len(items))
822822
return f"{jobs} | {elapsed_str(elapsed)} {earliest_proj}"
823823

824+
@classmethod
825+
def InitWorker(cls):
826+
# Force connect to the manager server now.
827+
# This is good because workers are initialized one by one. Without this,
828+
# multiple workers may connect to the manager when handling the first
829+
# job at the same time. Then the connection may fail if too many
830+
# connections are pending and execeeded the socket listening backlog,
831+
# especially on MacOS.
832+
len(cls.get_parallel_context()["sync_dict"])
833+
824834
def _Fetch(self, projects, opt, err_event, ssh_proxy, errors):
825835
ret = True
826836

@@ -913,6 +923,7 @@ def _ProcessResults(pool, pm, results_sets):
913923
# idle while other workers still have more than one job in
914924
# their chunk queue.
915925
chunksize=1,
926+
initializer=self.InitWorker,
916927
)
917928
finally:
918929
sync_event.set()

0 commit comments

Comments
 (0)