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

routing/http/client: avoid race by not using global http.Client #579

Merged
merged 3 commits into from
Feb 19, 2024

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Feb 15, 2024

Fixes the race condition observed in the tests in ipfs/rainbow#87.

It could've been fixed in rainbow, but that doesn't fix the source issue: we use the same global default HTTP client, while giving an option that can override its user agent. This option changes the user agent of the global variable, which may be used by multiple clients.

In addition, I updated the tests and documentations to reflect how WithUserAgent and WithHTTPClient work. The tests were passing until now by mistake and only because we were using the global defaultHTTPClient .

@hacdias hacdias self-assigned this Feb 15, 2024
@hacdias hacdias marked this pull request as ready for review February 15, 2024 08:28
@hacdias hacdias requested a review from a team as a code owner February 15, 2024 08:28
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (79cb4e2) 65.56% compared to head (eeef41d) 65.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #579      +/-   ##
==========================================
+ Coverage   65.56%   65.60%   +0.04%     
==========================================
  Files         207      207              
  Lines       25597    25612      +15     
==========================================
+ Hits        16782    16804      +22     
+ Misses       7336     7331       -5     
+ Partials     1479     1477       -2     
Files Coverage Δ
routing/http/client/client.go 73.00% <69.23%> (-1.60%) ⬇️

... and 10 files with indirect coverage changes

routing/http/client/client.go Outdated Show resolved Hide resolved
routing/http/client/client.go Outdated Show resolved Hide resolved
routing/http/client/client.go Outdated Show resolved Hide resolved
@hacdias hacdias requested a review from aschmahmann February 19, 2024 09:45
@hacdias
Copy link
Member Author

hacdias commented Feb 19, 2024

@aschmahmann I updated the options to return an error, and simplified the documentation of the options.

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good, left some documentation suggestions/clarifications

CHANGELOG.md Outdated Show resolved Hide resolved
routing/http/client/client.go Outdated Show resolved Hide resolved
@hacdias hacdias requested a review from aschmahmann February 19, 2024 10:05
@hacdias hacdias merged commit 39f4588 into main Feb 19, 2024
13 checks passed
@hacdias hacdias deleted the fix-race branch February 19, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants