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

feat: you can now supply your own HTTP agent to a web3.js Connection #29125

Merged
merged 4 commits into from
Dec 6, 2022
Merged

feat: you can now supply your own HTTP agent to a web3.js Connection #29125

merged 4 commits into from
Dec 6, 2022

Conversation

steveluscher
Copy link
Contributor

@steveluscher steveluscher commented Dec 6, 2022

Problem

There are folks who have good reasons to want to disable or override our default HTTP agent (ie. the thing that implements connection persistence in Node for the RPC). This PR keeps the behaviour of creating the usual default http.Agent, but offers config to disable or override it.

Disable it
new Connection(url, {httpAgent: false});
Supply your own
new Connection(url, {httpAgent: new https.Agent()});

Note, that if you supply your own, it's up to you to dispose of the agent when the connection is no longer needed.

Summary of Changes

  • Added an httpAgent config parameter to Connection
  • Auto-disable creating the default agent when process.env.NODE_ENV is test.

Fixes #25069.

@github-actions github-actions bot added the web3.js Related to the JavaScript client label Dec 6, 2022
@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Merging #29125 (05f5f5f) into master (4267a15) will decrease coverage by 0.4%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##           master   #29125     +/-   ##
=========================================
- Coverage    77.1%    76.7%   -0.5%     
=========================================
  Files          55       55             
  Lines        2934     3140    +206     
  Branches      408      472     +64     
=========================================
+ Hits         2264     2410    +146     
- Misses        529      565     +36     
- Partials      141      165     +24     

@steveluscher steveluscher merged commit f1427dd into solana-labs:master Dec 6, 2022
@steveluscher steveluscher deleted the injectable-http-agent branch December 6, 2022 22:57
gnapoli23 pushed a commit to gnapoli23/solana that referenced this pull request Dec 16, 2022
…olana-labs#29125)

* You can now supply your own `https?.Agent` when creating a `Connection` object

* Don't use HTTP agents in test mode

* Tests that assert the behaviour of the `agentOverride` config of `Connection`

* s/agentOverride/httpAgent/ is less confusing when the value is `false`
nickfrosty pushed a commit to nickfrosty/solana that referenced this pull request Jan 4, 2023
…olana-labs#29125)

* You can now supply your own `https?.Agent` when creating a `Connection` object

* Don't use HTTP agents in test mode

* Tests that assert the behaviour of the `agentOverride` config of `Connection`

* s/agentOverride/httpAgent/ is less confusing when the value is `false`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web3.js Related to the JavaScript client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

web3.js Connection http agent hanging tests and cli utilities
1 participant