Skip to content

Commit ee036b5

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

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
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;

0 commit comments

Comments
 (0)