Fix thread-safety issue in HTTP connection handling#31
Merged
Conversation
Remove memoization of Net::HTTP instance to prevent frozen SSL context errors when using concurrent requests. Each request now creates its own HTTP connection, ensuring thread-safety when using libraries like concurrent-ruby. This fixes the 'FrozenError: can't modify frozen OpenSSL::SSL::SSLContext' error that occurs when multiple threads try to use the same HTTP connection simultaneously. The overhead of creating a new HTTP connection per request is negligible compared to the actual API call time (which typically takes seconds).
oriolgual
reviewed
Nov 26, 2025
The method name 'http' was misleading as it suggested a memoized getter, but the implementation creates a fresh Net::HTTP instance on each call. Renaming to 'build_http' makes this factory pattern explicit and clarifies that each call creates a new connection with its own SSL context for thread-safety.
Makes the factory pattern more explicit by storing the HTTP instance in a local variable before using it. This improves code clarity and makes it obvious that each method gets its own connection instance.
oriolgual
approved these changes
Nov 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remove memoization of Net::HTTP instance to prevent frozen SSL context errors when using concurrent requests. Each request now creates its own HTTP connection, ensuring thread-safety when using libraries like concurrent-ruby.
This fixes the 'FrozenError: can't modify frozen OpenSSL::SSL::SSLContext' error that occurs when multiple threads try to use the same HTTP connection simultaneously.
The overhead of creating a new HTTP connection per request is negligible compared to the actual API call time (which typically takes seconds).