Fix thread-safety issue in HTTP::CookieJar loading #276
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.
HTTP::CookieJar uses unsafe class caching for dynamically loading cookie jar implementations. If 2 rest-client instances are instantiated at the same time, (for instance if you spawn 2 threads), then non-deterministic behaviour can occur whereby the Hash cookie jar isn't entirely loaded and cached. This sometimes raises an exception because the Hash CookieJar can't be found (it's a race condition)
See:
Forcing an instantiation of the jar onload will force the Hash CookieJar to load before the system has a chance to spawn any threads.
Note this should technically be fixed in rest-client itself however that library appears to be stagnant so we're forced to fix it here. This object should get GC'd as it's not referenced by anything
I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.