Make httpclient_adapter threadsafe #909
Merged
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.
httpclient_adapter uses some standard Ruby hashes, which produce unexpected results when working in a true multi-threaded (e.g. JRuby) environment. Multiple threads doing puts and deletes on these hashes result in nils sometimes being returned for a properly stubbed request. These errors would manifest as:
webmock-3.9.2/lib/webmock/http_lib_adapters/httpclient_adapter.rb:113:in build_httpclient_response: undefined method body for nil:NilClass (NoMethodError)
.Unfortunately these errors are extremely difficult to replicate. I've only been able to reproduce it periodically when running a large suite of VCR tests. Therefore its difficult to write a spec around this. I've run this patch against our local test suite over 10 times and haven't been able to reproduce the error with it, so I'm fairly confident in the fix. Not sure if the synchronization will hurt any other aspects of webmock performance?
This PR is a follow-on from #908, and represents the last thread-safety issue we've been able to find with our tests.