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

ffdec: Stop the ffmpeg process before closing any buffers #78

Merged
merged 1 commit into from Dec 26, 2018

Conversation

ssssam
Copy link
Contributor

@ssssam ssssam commented Dec 26, 2018

This fixes intermittent crashes that were introduced by commit
ac7b1e0.

In some situations the .close() method is called before the child
process has completed. If we close proc.stderr and proc.stdout while
a QueueReaderThread instance is still running, we get errors such as
this:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/sam/src/audioread/audioread/ffdec.py", line 73, in run
    data = self.fh.read(self.blocksize)
ValueError: I/O operation on closed file

Sometimes the CPython interpreter segfaults inside the io.read() call
before it can show this error.

We now kill the child process and wait for it to terminate before
closing the stdout and stderr pipes. This gives the queue reader threads
time to receive the end-of-file notifications from the pipes while they
are still open.

This fixes intermittent crashes that were introduced by commit
ac7b1e0.

In some situations the .close() method is called before the child
process has completed. If we close proc.stderr and proc.stdout while
a QueueReaderThread instance is still running, we get errors such as
this:

    Exception in thread Thread-2:
    Traceback (most recent call last):
      File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
        self.run()
      File "/home/sam/src/audioread/audioread/ffdec.py", line 73, in run
        data = self.fh.read(self.blocksize)
    ValueError: I/O operation on closed file

Sometimes the CPython interpreter segfaults inside the io.read() call
before it can show this error.

We now kill the child process and wait for it to terminate before
closing the stdout and stderr pipes. This gives the queue reader threads
time to receive the end-of-file notifications from the pipes while they
are still open.
@sampsyo
Copy link
Member

sampsyo commented Dec 26, 2018

Wow! This is a great, simple fix to a subtle problem. Thank you for doing the investigation to figure this out! ✨ 🚀

@sampsyo sampsyo merged commit 8d10f7b into beetbox:master Dec 26, 2018
sampsyo added a commit that referenced this pull request Dec 26, 2018
ffdec: Stop the ffmpeg process before closing any buffers
sampsyo added a commit that referenced this pull request Dec 26, 2018
@ssssam
Copy link
Contributor Author

ssssam commented Dec 26, 2018

No problem. Thanks for all your work on Beets :-)

@ssssam ssssam deleted the sam/ffdec-crash-fix branch December 26, 2018 18:06
@ssssam
Copy link
Contributor Author

ssssam commented Dec 27, 2018

This PR fixed my testcase, but it hasn't actually fixed the issue when doing a beet import :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants