Skip to content

Commit 33d6a3f

Browse files
committed
src: clean up StreamPipe in destructor
In the presence of Workers, it is not safe to assume that `StreamPipe::Unpipe()` has been called at the time when the object is destroyed. Instead, clean up when the destructor is called. PR-URL: #26256 Reviewed-By: Joyee Cheung <[email protected]>
1 parent 75ae77d commit 33d6a3f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/stream_pipe.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ StreamPipe::StreamPipe(StreamBase* source,
4242
}
4343

4444
StreamPipe::~StreamPipe() {
45-
CHECK(is_closed_);
45+
Unpipe();
4646
}
4747

4848
StreamBase* StreamPipe::source() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
const assert = require('assert');
6+
const http2 = require('http2');
7+
const makeDuplexPair = require('../common/duplexpair');
8+
const { Worker, isMainThread } = require('worker_threads');
9+
10+
// This is a variant of test-http2-generic-streams-sendfile for checking
11+
// that Workers can be terminated during a .respondWithFile() operation.
12+
13+
if (isMainThread) {
14+
return new Worker(__filename);
15+
}
16+
17+
{
18+
const server = http2.createServer();
19+
server.on('stream', common.mustCall((stream, headers) => {
20+
stream.respondWithFile(process.execPath); // Use a large-ish file.
21+
}));
22+
23+
const { clientSide, serverSide } = makeDuplexPair();
24+
server.emit('connection', serverSide);
25+
26+
const client = http2.connect('http://localhost:80', {
27+
createConnection: common.mustCall(() => clientSide)
28+
});
29+
30+
const req = client.request();
31+
32+
req.on('response', common.mustCall((headers) => {
33+
assert.strictEqual(headers[':status'], 200);
34+
}));
35+
36+
req.on('data', common.mustCall(process.exit));
37+
req.on('end', common.mustNotCall());
38+
req.end();
39+
}

0 commit comments

Comments
 (0)