-
Notifications
You must be signed in to change notification settings - Fork 1.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
Seahorse http connection pool may crash after fork(2) #3020
Comments
Thanks for opening an issue. I think we could fix the empty! method to not use iteration as well. We will investigate. |
Hi! We have a pending PR in efforts to resolve this issue. I will let you know when it is merged. I did noticed that you are using an older version of the aws-sdk-core ( |
This issue is now closed. Comments on closed issues are hard for our team to see. |
This fix will be released with tomorrow's update |
Thank you! |
Yes, that was our intention. We did an audit of the |
I think it will always be iterated, but I think the difference of whether it happens in C or Ruby when using fork is what matters. I think this should fix it for you! Thanks @jterapin for picking this up while I am away at RubyKaigi :) |
Describe the bug
If you call fork(2) when multi-threaded AWS API calls, some error may occur in the child process.
RuntimeError: can't add a new key into hash during iteration
occurs as reported in #1331.I think calling
Aws.empty_connection_pools!
after fork will prevent this crash, but resetting the connection pool usingAws.empty_connection_pools!
may be incomplete.In Aws.empty_connection_pools! we call Hash#clear on the hash that is pooling the http connection, but Hash#clear does not reset the state that it is iterating.
ref. https://github.com/ruby/ruby/blob/v3_1_5/hash.c#L2867-L2869
So, it may crash even if
Aws.empty_connection_pools!
is executed immediately after fork(2).Expected Behavior
We can prevent
RuntimeError: can't add a new key into hash during iteration
by discarding the seahorse connection pool after fork(2).Current Behavior
RuntimeError: can't add a new key into hash during iteration
may occurs even ifAws.empty_connection_pools!
is executed immediately after fork(2).Reproduction Steps
A simple ruby script for reproduction.
Executing the above script may causes
RuntimeError: can't add a new key into hash during iteration
.I checked with the following versions.
Possible Solution
More radical destruction is required to ensure that the connection pooling Hash is not reused in child processes.
I have confirmed that methods like below are effective to prevent the error
Adding this method to the reproduction script:
I have confirmed that no errors occur even after several hundred runs.
Additional Information/Context
No response
Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version
aws-sdk-core
Environment details (Version of Ruby, OS environment)
Ruby 3.1 (Our environment)
The text was updated successfully, but these errors were encountered: