diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-09-25 22:53:17 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-05-10 14:15:16 +0200 |
commit | 1db0039c505c6081f1d0d84cc24133ed6659e539 (patch) | |
tree | f6eab3adfb959b735d274f6c83790ef83834a21b /src/node_zlib.cc | |
parent | cac8496c2ff592198a7afd114610deccb0e178ab (diff) | |
download | android-node-v8-1db0039c505c6081f1d0d84cc24133ed6659e539.tar.gz android-node-v8-1db0039c505c6081f1d0d84cc24133ed6659e539.tar.bz2 android-node-v8-1db0039c505c6081f1d0d84cc24133ed6659e539.zip |
src: keep track of open requests
Workers cannot shut down while requests are open, so keep a counter
that is increased whenever libuv requests are made and decreased
whenever their callback is called.
This also applies to other embedders, who may want to shut down
an `Environment` instance early.
Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.
Fixes: https://github.com/nodejs/node/issues/20517
Refs: https://github.com/ayojs/ayo/pull/85
PR-URL: https://github.com/nodejs/node/pull/19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_zlib.cc')
-rw-r--r-- | src/node_zlib.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index ec447638e2..3249905dfb 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -214,6 +214,7 @@ class ZCtx : public AsyncWrap { } // async version + env->IncreaseWaitingRequestCounter(); uv_queue_work(env->event_loop(), work_req, ZCtx::Process, ZCtx::After); } @@ -361,10 +362,17 @@ class ZCtx : public AsyncWrap { // v8 land! static void After(uv_work_t* work_req, int status) { - CHECK_EQ(status, 0); - ZCtx* ctx = ContainerOf(&ZCtx::work_req_, work_req); Environment* env = ctx->env(); + ctx->write_in_progress_ = false; + + env->DecreaseWaitingRequestCounter(); + if (status == UV_ECANCELED) { + ctx->Close(); + return; + } + + CHECK_EQ(status, 0); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); @@ -374,7 +382,6 @@ class ZCtx : public AsyncWrap { ctx->write_result_[0] = ctx->strm_.avail_out; ctx->write_result_[1] = ctx->strm_.avail_in; - ctx->write_in_progress_ = false; // call the write() cb Local<Function> cb = PersistentToLocal(env->isolate(), |