Skip to content

Commit 7dfbf7e

Browse files
committed
fixup! http: improve performance by removing async_hooks
1 parent 447db0b commit 7dfbf7e

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ function resOnFinish(req, res, socket, state, server) {
996996
// If the user never called req.read(), and didn't pipe() or
997997
// .resume() or .on('data'), then we call req._dump() so that the
998998
// bytes will be pulled off the wire.
999-
if (!req._consuming && !req._readableState.resumeScheduled)
999+
if (!req._consuming && !req._readableState.resumeScheduled && !req._readableState.paused)
10001000
req._dump();
10011001

10021002
res.detachSocket(socket);

src/node_http_parser.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ class Parser : public BaseObject, public StreamListener {
464464

465465
Local<Value> buffer = Buffer::Copy(env, at, length).ToLocalChecked();
466466

467-
MaybeLocal<Value> r =
468-
cb.As<Function>()->Call(env->context(), object(), 1, &buffer);
467+
v8::TryCatch try_catch(env->isolate());
468+
USE(cb.As<Function>()->Call(env->context(), object(), 1, &buffer));
469469

470-
if (r.IsEmpty()) {
470+
if (try_catch.HasCaught()) {
471471
got_exception_ = true;
472472
llhttp_set_error_reason(&parser_, "HPE_JS_EXCEPTION:JS Exception");
473473
return HPE_USER;
@@ -503,9 +503,11 @@ class Parser : public BaseObject, public StreamListener {
503503
if (!cb->IsFunction())
504504
return 0;
505505

506-
MaybeLocal<Value> r =
507-
cb.As<Function>()->Call(env()->context(), object(), 0, nullptr);
508-
if (r.IsEmpty()) {
506+
507+
v8::TryCatch try_catch(env()->isolate());
508+
USE(cb.As<Function>()->Call(env()->context(), object(), 0, nullptr));
509+
510+
if (try_catch.HasCaught()) {
509511
got_exception_ = true;
510512
return -1;
511513
}
@@ -782,8 +784,14 @@ class Parser : public BaseObject, public StreamListener {
782784
current_buffer_len_ = nread;
783785
current_buffer_data_ = buf.base;
784786

787+
v8::TryCatch try_catch(env()->isolate());
785788
USE(cb.As<Function>()->Call(env()->context(), object(), 1, &ret));
786789

790+
if (try_catch.HasCaught()) {
791+
got_exception_ = true;
792+
return;
793+
}
794+
787795
current_buffer_len_ = 0;
788796
current_buffer_data_ = nullptr;
789797
}
@@ -897,10 +905,12 @@ class Parser : public BaseObject, public StreamListener {
897905
url_.ToString(env())
898906
};
899907

900-
if (cb.As<Function>()
901-
->Call(env()->context(), object(), arraysize(argv), argv)
902-
.IsEmpty())
908+
v8::TryCatch try_catch(env()->isolate());
909+
USE(cb.As<Function>()->Call(env()->context(), object(), arraysize(argv), argv));
910+
911+
if (try_catch.HasCaught()) {
903912
got_exception_ = true;
913+
}
904914

905915
url_.Reset();
906916
have_flushed_ = true;

test/parallel/test-http-parser.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,6 @@ function expectBody(expected) {
518518
'0\r\n'
519519
);
520520

521-
const req2 = Buffer.from(
522-
'POST /that HTTP/1.0\r\n' +
523-
'Content-Type: text/plain\r\n' +
524-
'Content-Length: 4\r\n' +
525-
'\r\n' +
526-
'pong'
527-
);
528-
529521
const onHeadersComplete1 = (versionMajor, versionMinor, headers,
530522
method, url) => {
531523
assert.strictEqual(method, methods.indexOf('PUT'));
@@ -537,18 +529,6 @@ function expectBody(expected) {
537529
['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']);
538530
};
539531

540-
const onHeadersComplete2 = (versionMajor, versionMinor, headers,
541-
method, url) => {
542-
assert.strictEqual(method, methods.indexOf('POST'));
543-
assert.strictEqual(url, '/that');
544-
assert.strictEqual(versionMajor, 1);
545-
assert.strictEqual(versionMinor, 0);
546-
assert.deepStrictEqual(
547-
headers,
548-
['Content-Type', 'text/plain', 'Content-Length', '4']
549-
);
550-
};
551-
552532
const parser = newParser(REQUEST);
553533
parser[kOnHeadersComplete] = onHeadersComplete1;
554534
parser[kOnBody] = expectBody('ping');

0 commit comments

Comments
 (0)