File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -330,7 +330,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
330
330
const typedError = error as RequestError ;
331
331
332
332
void ( async ( ) => {
333
- if ( response && ! response . rawBody ) {
333
+ // Node.js parser is really weird.
334
+ // It emits post-request Parse Errors on the same instance as previous request. WTF.
335
+ // Therefore we need to check if it has been destroyed as well.
336
+ if ( response && ! response . rawBody && ! this . _request ?. destroyed ) {
334
337
// @types /node has incorrect typings. `setEncoding` accepts `null` as well.
335
338
response . setEncoding ( this . readableEncoding ! ) ;
336
339
Original file line number Diff line number Diff line change @@ -254,6 +254,31 @@ test('no uncaught parse errors', async t => {
254
254
await close ( ) ;
255
255
} ) ;
256
256
257
+ test ( 'no uncaught parse errors #2' , async t => {
258
+ const server = net . createServer ( ) ;
259
+
260
+ const listen = promisify ( server . listen . bind ( server ) ) ;
261
+ const close = promisify ( server . close . bind ( server ) ) ;
262
+
263
+ await listen ( ) ;
264
+
265
+ server . on ( 'connection' , socket => {
266
+ socket . resume ( ) ;
267
+ socket . write ( [
268
+ 'HTTP/1.1 200 OK' ,
269
+ 'content-length: 1' ,
270
+ '' ,
271
+ '0a'
272
+ ] . join ( '\r\n' ) ) ;
273
+ } ) ;
274
+
275
+ await t . throwsAsync ( got ( `http://localhost:${ ( server . address ( ) as net . AddressInfo ) . port } ` ) , {
276
+ message : / ^ P a r s e E r r o r /
277
+ } ) ;
278
+
279
+ await close ( ) ;
280
+ } ) ;
281
+
257
282
// Fails randomly on Node 10:
258
283
// Blocked by https://github.com/istanbuljs/nyc/issues/619
259
284
// eslint-disable-next-line ava/no-skip-test
You can’t perform that action at this time.
0 commit comments