-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: invoke callback with ERR_STREAM_DESTROYED if the socket is dest…
…royed Fixes: #36673 Refs: #29227 (comment)
- Loading branch information
Showing
2 changed files
with
115 additions
and
75 deletions.
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,61 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { createServer, request } = require('http'); | ||
|
||
{ | ||
const server = createServer((req, res) => { | ||
server.close(); | ||
|
||
req.socket.destroy(); | ||
|
||
res.write('hello', common.expectsError({ | ||
code: 'ERR_STREAM_DESTROYED' | ||
})); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const req = request({ | ||
host: 'localhost', | ||
port: server.address().port | ||
}); | ||
|
||
req.on('response', common.mustNotCall()); | ||
req.on('error', common.expectsError({ | ||
code: 'ECONNRESET' | ||
})); | ||
|
||
req.end(); | ||
})); | ||
} | ||
|
||
{ | ||
const server = createServer((req, res) => { | ||
res.write('hello'); | ||
req.resume(); | ||
|
||
const onError = common.expectsError({ | ||
code: 'ERR_STREAM_DESTROYED' | ||
}); | ||
|
||
res.on('close', () => { | ||
res.write('world', common.mustCall((err) => { | ||
onError(err); | ||
server.close(); | ||
})); | ||
}); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const req = request({ | ||
host: 'localhost', | ||
port: server.address().port | ||
}); | ||
|
||
req.on('response', common.mustCall((res) => { | ||
res.socket.destroy(); | ||
})); | ||
|
||
req.end(); | ||
})); | ||
} |