File tree Expand file tree Collapse file tree 5 files changed +30
-25
lines changed
hardhat-core/src/internal/util Expand file tree Collapse file tree 5 files changed +30
-25
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " hardhat " : patch
3
+ " @nomicfoundation/hardhat-verify " : patch
4
+ ---
5
+
6
+ Don't use ` undici ` 's global dispatcher, making Hardhat more stable across Node.js versions
Original file line number Diff line number Diff line change @@ -24,13 +24,13 @@ export async function download(
24
24
timeoutMillis = 10000 ,
25
25
extraHeaders : { [ name : string ] : string } = { }
26
26
) {
27
- const { getGlobalDispatcher , ProxyAgent, request } = await import ( "undici" ) ;
27
+ const { Agent , ProxyAgent, request } = await import ( "undici" ) ;
28
28
29
29
let dispatcher : Dispatcher ;
30
30
if ( process . env . http_proxy !== undefined && shouldUseProxy ( url ) ) {
31
31
dispatcher = new ProxyAgent ( process . env . http_proxy ) ;
32
32
} else {
33
- dispatcher = getGlobalDispatcher ( ) ;
33
+ dispatcher = new Agent ( ) ;
34
34
}
35
35
36
36
const hardhatVersion = getHardhatVersion ( ) ;
Original file line number Diff line number Diff line change @@ -28,14 +28,25 @@ export async function sendPostRequest(
28
28
} ) ;
29
29
}
30
30
31
+ let mockDispatcher : Undici . Dispatcher | undefined ;
32
+
31
33
function getDispatcher ( ) : Undici . Dispatcher {
32
- const { ProxyAgent, getGlobalDispatcher } =
33
- require ( "undici" ) as typeof Undici ;
34
+ if ( mockDispatcher !== undefined ) {
35
+ return mockDispatcher ;
36
+ }
37
+
38
+ const { ProxyAgent, Agent } = require ( "undici" ) as typeof Undici ;
34
39
if ( process . env . http_proxy !== undefined ) {
35
40
return new ProxyAgent ( process . env . http_proxy ) ;
36
41
}
37
42
38
- return getGlobalDispatcher ( ) ;
43
+ return new Agent ( ) ;
44
+ }
45
+
46
+ export function setMockDispatcher (
47
+ dispatcher : Undici . Dispatcher | undefined
48
+ ) : void {
49
+ mockDispatcher = dispatcher ;
39
50
}
40
51
41
52
export function isSuccessStatusCode ( statusCode : number ) : boolean {
Original file line number Diff line number Diff line change 1
- import {
2
- Dispatcher ,
3
- getGlobalDispatcher ,
4
- MockAgent ,
5
- setGlobalDispatcher ,
6
- } from "undici" ;
1
+ import { MockAgent } from "undici" ;
2
+ import { setMockDispatcher } from "../../../src/internal/undici" ;
7
3
8
4
const mockAgent = new MockAgent ( {
9
5
keepAliveTimeout : 10 ,
@@ -13,17 +9,15 @@ const mockAgent = new MockAgent({
13
9
const client = mockAgent . get ( "https://api-hardhat.etherscan.io" ) ;
14
10
15
11
export const mockEnvironment = ( ) => {
16
- let globalDispatcher : Dispatcher ;
17
12
// enable network connections for everything but etherscan API
18
13
mockAgent . enableNetConnect ( / ^ (? ! h t t p s : \/ \/ a p i - h a r d h a t \. e t h e r s c a n \. i o ) / ) ;
19
14
20
15
before ( ( ) => {
21
- globalDispatcher = getGlobalDispatcher ( ) ;
22
- setGlobalDispatcher ( mockAgent ) ;
16
+ setMockDispatcher ( mockAgent ) ;
23
17
} ) ;
24
18
25
19
after ( ( ) => {
26
- setGlobalDispatcher ( globalDispatcher ) ;
20
+ setMockDispatcher ( undefined ) ;
27
21
} ) ;
28
22
} ;
29
23
Original file line number Diff line number Diff line change 1
- import {
2
- Dispatcher ,
3
- getGlobalDispatcher ,
4
- MockAgent ,
5
- setGlobalDispatcher ,
6
- } from "undici" ;
1
+ import { MockAgent } from "undici" ;
2
+ import { setMockDispatcher } from "../../../src/internal/undici" ;
7
3
8
4
const mockAgent = new MockAgent ( {
9
5
keepAliveTimeout : 10 ,
@@ -13,17 +9,15 @@ const mockAgent = new MockAgent({
13
9
const client = mockAgent . get ( "https://sourcify.dev" ) ;
14
10
15
11
export const mockEnvironmentSourcify = ( ) => {
16
- let globalDispatcher : Dispatcher ;
17
12
// enable network connections for everything but etherscan API
18
13
mockAgent . enableNetConnect ( / ^ (? ! h t t p s : \/ \/ s o u r c i f y \. d e v ) / ) ;
19
14
20
15
before ( ( ) => {
21
- globalDispatcher = getGlobalDispatcher ( ) ;
22
- setGlobalDispatcher ( mockAgent ) ;
16
+ setMockDispatcher ( mockAgent ) ;
23
17
} ) ;
24
18
25
19
after ( ( ) => {
26
- setGlobalDispatcher ( globalDispatcher ) ;
20
+ setMockDispatcher ( undefined ) ;
27
21
} ) ;
28
22
} ;
29
23
You can’t perform that action at this time.
0 commit comments