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

Make httpclient_adapter threadsafe #909

Merged
merged 1 commit into from Oct 16, 2020
Merged

Conversation

adam-harwood
Copy link
Contributor

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.

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 extremly difficult to replicate.

This PR is a follow-on from bblimke#908, and represents the last thread-safety issue we've been able to find.
@bblimke
Copy link
Owner

bblimke commented Oct 16, 2020

Thank you @adam-harwood

I think this can only hurt other aspects of WebMock performance in a multi-threaded environment,
which requires that fix anyway, therefore it's better to have this patched, whether it affects performance or not.

@bblimke bblimke merged commit a5991c7 into bblimke:master Oct 16, 2020
@bblimke
Copy link
Owner

bblimke commented Oct 16, 2020

It's now released as version 3.9.3

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