Repository navigation
the Stream is closed if app pushes unused assets #20824
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.http2Issues and PRs related to the http2 subsystem.Issues and PRs related to the http2 subsystem.
Description
- Version: 10.1.0
- Platform: Windows Server 2008R2 64
- Subsystem: any browser any OS
If push some assets which will not be used with browser - stream closes on the second request
Page requires only <script src="script.js"></script>, but if to push something that is not using on the page - the next page refresh will close the http2 stream
const pushAsset = (stream, file) => {
const filePath = path.resolve(file.filePath);
stream.pushStream({ [HTTP2_HEADER_PATH]: file.path }, (err, pushStream) => {
pushStream.respondWithFile(filePath, file.headers, {
onError: (err) => {
respondToStreamError(err, stream);
}
});
});
};
const cssFile = {
path: '/style.css',
filePath: './style.css',
headers: {
'content-type': 'text/css'
}
};
const cssFile1 = {
path: '/style1.css',
filePath: './style1.css',
headers: {
'content-type': 'text/css'
}
};
const jsFile = {
path: '/script.js',
filePath: './script.js',
headers: {
'content-type': 'application/javascript'
}
};
pushAsset(stream, jsFile);
pushAsset(stream, cssFile); //<-- unused
pushAsset(stream, cssFile1); //<-- unusedThe error:
events.js:167
throw er; // Unhandled 'error' event
^
Error [ERR_HTTP2_STREAM_ERROR]: Stream closed with error code NGHTTP2_REFUSED_STREAM
at ServerHttp2Stream._destroy (internal/http2/core.js:1871:13)
at ServerHttp2Stream.destroy (internal/streams/destroy.js:32:8)
at ServerHttp2Stream.[maybe-destroy] (internal/http2/core.js:1887:12)
at Http2Stream.onStreamClose [as onstreamclose] (internal/http2/core.js:346:26)
Emitted 'error' event at:
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
Declaration of extra assets should not crush the tream
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.http2Issues and PRs related to the http2 subsystem.Issues and PRs related to the http2 subsystem.
Activity
[-]Stream closes when app pushes unused assets[/-][+]the Stream is closed if app pushes unused assets[/+]budarin commentedon May 19, 2018
Here is the demo project
try to uncomment these lines:
and make some quick page refreshes - it makes the error.
ryzokuken commentedon May 21, 2018
/cc @nodejs/http2
apapirovski commentedon May 21, 2018
This seems as expected to me. Add an error handler that ignores
NGHTTP2_REFUSED_STREAMerrors. See the spec: https://http2.github.io/http2-spec/#rfc.section.7budarin commentedon May 21, 2018
@apapirovski
I'm sorry, could you provide the code, please.
I don't quite understand what you mean.
apapirovski commentedon May 21, 2018
Sorry, should've been clearer, you can use something like this to make sure those errors don't take down your app:
budarin commentedon May 21, 2018
It didnt helped - after some refreshes here is another error:
Please review the code:
budarin commentedon May 21, 2018
And even not pushing unnessesary assets, but quickly refresh the page - you will get the error:
apapirovski commentedon May 21, 2018
Sounds like there are potentially issues in our C++ pipe code.
ping @addaleax
ryzokuken commentedon May 21, 2018
@budarin I could take a look into this, but could you bring me up to speed by sharing the complete relevant code for the server script? Or is the
streamobject a simple newly initialized stream?budarin commentedon May 21, 2018
here is the repository for experiments and testing http2 project
ryzokuken commentedon May 21, 2018
@budarin Umm, I uncommented the two lines and reloaded, the page loads up as expected. That said, I'm using chrome to connect. Hope that's not an issue?
ryzokuken commentedon May 21, 2018
The two JavaScript files don't show up here, though? I think that's expected anyway.
16 remaining items
addaleax commentedon Jun 3, 2018
I think this would work:
It only creates one of the failure modes, though.
DaAitch commentedon Jun 3, 2018
@addaleax you're right it failes:
node[9901]: ../src/node_file.cc:220:v8::MaybeLocal<v8::Promise> node::fs::FileHandle::ClosePromise(): Assertion '!reading_' failed.I'm wondering if
CHECK(!reading_);is correct inFileHandle::ClosePromise, sinceAfterClosewill handle aFileHandlebeing in reading state.And how do we get this second error I was talking about?
node[4683]: ../src/node_http2.cc:1966:virtual int node::http2::Http2Stream::DoWrite(node::WriteWrap*, uv_buf_t*, size_t, uv_stream_t*): Assertion '!this->IsDestroyed()' failed.addaleax commentedon Jun 3, 2018
@DaAitch I think the check is correct, it’s rather that the
StreamPipeimplementation shouldn’t keep reading if there was an error on the writable side. This is a patch that fixes this problem, but it’s (obviously?) not an ideal solution:That second error is probably coming from a similar condition as the one from that test, but with different timing properties (but I’m not sure about that).
DaAitch commentedon Jun 3, 2018
@addaleax the patch you provided gives me a green test, but segfaults in my manual test.
edited: I only pasted SIGPIPE, forgot to continue to SIGSEGV.
ariran5 commentedon Jun 20, 2018
I have this problem too
if add this code
its work, but if i often reload page then node crash
apapirovski commentedon Jun 24, 2018
I'm going to spend some time with this today, hopefully I'll get to the point where I can make a PR.
apapirovski commentedon Jun 25, 2018
@addaleax Are you still able to reproduce? Because I tried against 10.5.0 with all 3 examples in this thread and I can't get it to fail...
http2: fix issues with aborted `respondWithFile()`s
http2: fix issues with aborted `respondWithFile()`s
http2: fix issues with aborted `respondWithFile()`s