Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock with parallel SBY procs each with parallel tasks #245

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sbysrc/sby_jobserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ def process_jobserver_environment():

def jobserver_helper(jobserver_read_fd, jobserver_write_fd, request_fd, response_fd):
"""Helper process to handle blocking jobserver pipes."""
def handle_sigusr1(*args):
# Since Python doesn't allow user code to handle EINTR anymore, we replace the
# jobserver fd with an fd at EOF to interrupt a blocking read in a way that
# cannot lose any read data
r, w = os.pipe()
os.close(w)
os.dup2(r, jobserver_read_fd)
os.close(r)
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGUSR1, handle_sigusr1)
pending = 0
while True:
try:
Expand Down Expand Up @@ -110,6 +119,8 @@ def jobserver_helper(jobserver_read_fd, jobserver_write_fd, request_fd, response
except BlockingIOError:
select.select([jobserver_read_fd], [], [])
continue
if not token:
break

pending -= 1

Expand Down Expand Up @@ -240,6 +251,10 @@ def atexit_blocking(self):
# Closing the request pipe singals the helper that we want to exit
os.close(self.request_write_fd)

# Additionally we send a signal to interrupt a blocking read within the
# helper
self.helper_process.send_signal(signal.SIGUSR1)

# The helper might have been in the process of sending us some tokens, which
# we still need to return
while True:
Expand Down