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 ld-decode deadlock on exit. #394

Merged
merged 1 commit into from
Jan 1, 2020
Merged

Conversation

atsampson
Copy link
Collaborator

On machines with small numbers of CPUs (e.g. the GitHub CI machines!), ld-decode would sometimes deadlock on exit, with two threads in different processes blocked reading from pipes.

This turned out to be a race in the DemodCache destructor. It was doing:

for i in self.threads:
    if i.is_alive():
        self.q_in.put(None)

with the workers exiting when they received a None message. However, suppose you've got two workers, and the following happens:

  • DemodCache checks if A is alive - it is
  • DemodCache sends None
  • B receives None and exits
  • DemodCache checks if B is alive - it isn't

A is now stuck waiting for a message that'll never arrive. I've fixed this by removing the is_alive checks -- so it may now send more None messages than necessary, but that's harmless.

On machines with small numbers of CPUs, ld-decode would sometimes
deadlock on exit, with two threads in different processes blocked
reading from pipes.

This turned out to be a race in the DemodCache destructor. It was doing:

for i in self.threads:
    if i.is_alive():
        self.q_in.put(None)

with the workers exiting when they received a None message. However,
suppose you've got two workers, and the following happens:

- DemodCache checks if A is alive - it is
- DemodCache sends None
- B receives None and exits
- DemodCache checks if B is alive - it isn't

A is now stuck waiting for a message that'll never arrive. I've fixed
this by removing the is_alive checks -- so it may now send more None
messages than necessary, but that's harmless.
@atsampson atsampson added bug ld-decode An issue only affecting the ld-decode[r] labels Dec 31, 2019
Copy link
Owner

@happycube happycube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) The original version is a bit silly.

@happycube happycube merged commit 9303587 into happycube:master Jan 1, 2020
@atsampson atsampson deleted the fixdeadlock branch January 6, 2020 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ld-decode An issue only affecting the ld-decode[r]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants