GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: fix issues with aborted `respondWithFile()`s by addaleax · Pull Request #21561 · nodejs/node

http2: fix issues with aborted respondWithFile()s #21561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
addaleax wants to merge 2 commits into nodejs:master from addaleax:http2-stream-pipe

Uh oh!

There was an error while loading. Please reload this page.

Closed

http2: fix issues with aborted respondWithFile()s #21561

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
bb4e94a
http2: fix issues with aborted `respondWithFile()`s
addaleax Jun 27, 2018
6a04dbe
[squash] hack around error in test
addaleax Jul 15, 2018
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

3 changes: 1 addition & 2 deletions 3 src/node_http2.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2060,10 +2060,9 @@ int Http2Stream::DoWrite(WriteWrap* req_wrap,
uv_buf_t* bufs,
size_t nbufs,
uv_stream_t* send_handle) {
CHECK(!this->IsDestroyed());
CHECK_NULL(send_handle);
Http2Scope h2scope(this);
if (!IsWritable()) {
if (!IsWritable() || IsDestroyed()) {
req_wrap->Done(UV_EOF);
return 0;
}
Expand Down
11 changes: 8 additions & 3 deletions 11 src/stream_pipe.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ void StreamPipe::Unpipe() {
if (is_closed_)
return;

// Note that we cannot use virtual methods on `source` and `sink` here,
// because this function can be called from their destructors via
// Note that we possibly cannot use virtual methods on `source` and `sink`
// here, because this function can be called from their destructors via
// `OnStreamDestroy()`.
if (!source_destroyed_)
source()->ReadStop();

is_closed_ = true;
is_reading_ = false;
Expand Down Expand Up @@ -144,7 +146,8 @@ void StreamPipe::ProcessData(size_t nread, const uv_buf_t& buf) {
is_writing_ = true;
is_reading_ = false;
res.wrap->SetAllocatedStorage(buf.base, buf.len);
source()->ReadStop();
if (source() != nullptr)
source()->ReadStop();
}
}

Expand Down Expand Up @@ -183,13 +186,15 @@ void StreamPipe::WritableListener::OnStreamAfterShutdown(ShutdownWrap* w,

void StreamPipe::ReadableListener::OnStreamDestroy() {
StreamPipe* pipe = ContainerOf(&StreamPipe::readable_listener_, this);
pipe->source_destroyed_ = true;
if (!pipe->is_eof_) {
OnStreamRead(UV_EPIPE, uv_buf_init(nullptr, 0));
}
}

void StreamPipe::WritableListener::OnStreamDestroy() {
StreamPipe* pipe = ContainerOf(&StreamPipe::writable_listener_, this);
pipe->sink_destroyed_ = true;
pipe->is_eof_ = true;
pipe->Unpipe();
}
Expand Down
10 changes: 6 additions & 4 deletions 10 src/stream_pipe.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ class StreamPipe : public AsyncWrap {
}

private:
StreamBase* source();
StreamBase* sink();
inline StreamBase* source();
inline StreamBase* sink();

void ShutdownWritable();
void FlushToWritable();
inline void ShutdownWritable();
inline void FlushToWritable();

bool is_reading_ = false;
bool is_writing_ = false;
bool is_eof_ = false;
bool is_closed_ = true;
bool sink_destroyed_ = false;
bool source_destroyed_ = false;

// Set a default value so that when we’re coming from Start(), we know
// that we don’t want to read just yet.
Expand Down
37 changes: 37 additions & 0 deletions 37 test/parallel/test-http2-respond-with-file-connection-abort.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const net = require('net');

const {
HTTP2_HEADER_CONTENT_TYPE
} = http2.constants;

const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.respondWithFile(process.execPath, {
[HTTP2_HEADER_CONTENT_TYPE]: 'application/octet-stream'
});
}));

server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();

req.on('response', common.mustCall(() => {}));
req.on('data', common.mustCall(() => {
net.Socket.prototype.destroy.call(client.socket);
server.close();
}));
req.end();
}));

// TODO(addaleax): This is a *hack*. HTTP/2 needs to have a proper way of
// dealing with this kind of issue.
process.once('uncaughtException', (err) => {
if (err.code === 'ECONNRESET') return;
throw err;
});
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.