-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 hanging Ctrl+C on S3 downloads #673
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a regression that was introduced when the IO queue/thread was introduced (aws#619). The current shutdown order of the threads is: 1. Queue end sentinel for IO thread. 2. Queue end sentinel for result thread. 3. Queue end sentinel for worker threads. 4. .join() threads in this order: [io_thread, result_thread [, worker threads]] Though the actual thread shutdown order is non-deterministic, it's fairly common that the threads shutdown in roughly the above order. This means that the IO thread will generally shutdown before all the worker threads have shutdown. However, the download tasks can still be enqueueing writes to the IO queue. If the IO thread shutsdown there's nothing consuming writes on the other end of the queue. Given that the queue is bounded in maxsize, .put() calls to the queue will block until space becomes available. This will never happen if the IO queue is already shutdown. The fix here is to ensure that the IO thread is always the last thing to shutdown. This means any remaining IO requests will be executed before the IO thread shutsdown. This will prevent deadlock. Added unit tests demonstrates this issue. I've also added an integration test that actually sends a SIGINT to the process and verifies it exits in a timely manner so can ensure we don't regress on this again. Note: some unit/integ tests needed updating because they were using .call() multiple times. Fixes aws#650 Fixes aws#657
while time.time() < deadline: | ||
rc = process.poll() | ||
if rc is not None: | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to put a short time.sleep
here? How long does this test typically take to run? Up to 30 seconds seems like a long time to busy loop.
Great find and fix. LGTM 🚢-it. |
LGTM as well. |
Fallout from removal of .done and .interrupt.
It's possible that between the isdir() check and the makedirs() check that another thread has come along and created the directory. We also need to make sure that any uncaught exception will cause the download to be cancelled.
I've added some addition fixes. @toastdriven mind taking a look? |
Still LGTM. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a regression that was introduced when the IO queue/thread
was introduced (#619).
The current shutdown order of the threads is:
[io_thread, result_thread [, worker threads]]
Though the actual thread shutdown order is non-deterministic,
it's fairly common that the threads shutdown in roughly the above
order. This means that the IO thread will generally shutdown before
all the worker threads have shutdown.
However, the download tasks can still be enqueueing writes to the
IO queue. If the IO thread shutsdown there's nothing consuming
writes on the other end of the queue. Given that the queue is
bounded in maxsize, .put() calls to the queue will block until space
becomes available. This will never happen if the IO queue is already
shutdown.
The fix here is to ensure that the IO thread is always the last thing
to shutdown. This means any remaining IO requests will be executed
before the IO thread shutsdown. This will prevent deadlock.
Added unit tests demonstrates this issue. I've also added an
integration test that actually sends a SIGINT to the process
and verifies it exits in a timely manner so can ensure we
don't regress on this again.
Note: some unit/integ tests needed updating because they were
using .call() multiple times.
Fixes #650
Fixes #657