-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: make timeout event work with agent timeout
The `'timeout'` event is currently not emitted on the `ClientRequest` instance when the socket timeout expires if only the `timeout` option of the agent is set. This happens because, under these circumstances, `listenSocketTimeout()` is not called. This commit fixes the issue by calling it also when only the agent `timeout` option is set. PR-URL: #25488 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const { expectsError, mustCall } = require('../common'); | ||
const { Agent, get } = require('http'); | ||
|
||
// Test that the `'timeout'` event is emitted on the `ClientRequest` instance | ||
// when the socket timeout set via the `timeout` option of the `Agent` expires. | ||
|
||
const request = get({ | ||
agent: new Agent({ timeout: 500 }), | ||
// Non-routable IP address to prevent the connection from being established. | ||
host: '192.0.2.1' | ||
}); | ||
|
||
request.on('error', expectsError({ | ||
type: Error, | ||
code: 'ECONNRESET', | ||
message: 'socket hang up' | ||
})); | ||
|
||
request.on('timeout', mustCall(() => { | ||
request.abort(); | ||
})); |