-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Address unbounded memory growth in upload_stream when source outpaces upload #3407
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
base: version-3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ class DefaultExecutor | |
| def initialize(options = {}) | ||
| @max_threads = options[:max_threads] || DEFAULT_MAX_THREADS | ||
| @state = RUNNING | ||
| @queue = Queue.new | ||
| @queue = SizedQueue.new(@max_threads) | ||
| @pool = [] | ||
| @mutex = Mutex.new | ||
| end | ||
|
|
@@ -25,9 +25,9 @@ def post(*args, &block) | |
| @mutex.synchronize do | ||
| raise 'Executor has been shutdown and is no longer accepting tasks' unless @state == RUNNING | ||
|
|
||
| @queue << [args, block] | ||
| ensure_worker_available | ||
| end | ||
| @queue << [args, block] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You moved the enqueue out of the mutex to avoid holding the lock while parked but what happens |
||
| true | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,18 +113,21 @@ def complete_opts(options) | |
| def read_to_part_body(read_pipe) | ||
| return if read_pipe.closed? | ||
|
|
||
| temp_io = @tempfile ? Tempfile.new('aws-sdk-s3-upload_stream') : StringIO.new(String.new) | ||
| temp_io.binmode | ||
| bytes_copied = IO.copy_stream(read_pipe, temp_io, @part_size) | ||
| temp_io.rewind | ||
| if bytes_copied.zero? | ||
| if temp_io.is_a?(Tempfile) | ||
| if @tempfile | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding: What's the reason for the split here? The tempfile branch needs |
||
| temp_io = Tempfile.new('aws-sdk-s3-upload_stream') | ||
| temp_io.binmode | ||
| bytes_copied = IO.copy_stream(read_pipe, temp_io, @part_size) | ||
| temp_io.rewind | ||
| if bytes_copied.zero? | ||
| temp_io.close | ||
| temp_io.unlink | ||
| nil | ||
| else | ||
| temp_io | ||
| end | ||
| nil | ||
| else | ||
| temp_io | ||
| data = read_pipe.read(@part_size) | ||
| data.nil? || data.empty? ? nil : StringIO.new(data) | ||
| end | ||
| end | ||
|
|
||
|
|
||
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.
I think its worthwhile to offer
@max_queueas a separate option and pass in a reasonable default to:max_queuewhen creating an executor within the scope of the streaming uploader.