Prevent fetching the user agent concurrently #1205
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.
r? @dcr-stripe
cc @stripe/api-libraries
Motivation
Fixes #1202
Summary
Right now, when calculating the proper user agent, we check a cache and shell out to
uname
if the cache is empty. This is bad because we can shell out touname
multiple times concurrently before the cache is populated. For some bulk operation usage patterns this causes an unwanted CPU spike (see #1202). It would be better to only shell out once.This PR makes two changes:
uname
directly, instead of the deriveduser_agent
. This allows me to remove some questionable cache invalidation. We should only ever need to calluname
once,uname
is not expected to change.Breakingness:
Stripe.USER_AGENT_SERIALIZED isn't marked as private, but I think we should consider it safe to just remove this property. It was an internal cache and I cannot imagine any legitimate use case relying on it.
Tests
Existing tests for
getClientUserAgent
pass.