Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

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`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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