Skip to content

Commit 30b7349

Browse files
committed
stream_base: dispatch reqs in the stream impl
Dispatch requests in the implementation of the stream, not in the code creating these requests. The requests might be piled up and invoked internally in the implementation, so it should know better when it is the time to dispatch them. In fact, TLS was doing exactly this thing which led us to... Fix: nodejs#1512 PR-URL: nodejs#1563 Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent 78f4b03 commit 30b7349

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/js_stream.cc

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
7171
req_wrap->object()
7272
};
7373

74+
req_wrap->Dispatched();
7475
Local<Value> res =
7576
MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv);
7677

@@ -95,6 +96,7 @@ int JSStream::DoWrite(WriteWrap* w,
9596
bufs_arr
9697
};
9798

99+
w->Dispatched();
98100
Local<Value> res =
99101
MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv);
100102

src/stream_base.cc

-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
6060
AfterShutdown);
6161

6262
int err = DoShutdown(req_wrap);
63-
req_wrap->Dispatched();
6463
if (err)
6564
delete req_wrap;
6665
return err;
@@ -181,7 +180,6 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
181180
if (bufs != bufs_)
182181
delete[] bufs;
183182

184-
req_wrap->Dispatched();
185183
req_wrap->object()->Set(env->async(), True(env->isolate()));
186184
req_wrap->object()->Set(env->bytes_string(),
187185
Number::New(env->isolate(), bytes));
@@ -228,7 +226,6 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
228226
req_wrap = WriteWrap::New(env, req_wrap_obj, this, AfterWrite);
229227

230228
err = DoWrite(req_wrap, bufs, count, nullptr);
231-
req_wrap->Dispatched();
232229
req_wrap_obj->Set(env->async(), True(env->isolate()));
233230

234231
if (err)
@@ -347,7 +344,6 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
347344
reinterpret_cast<uv_stream_t*>(send_handle));
348345
}
349346

350-
req_wrap->Dispatched();
351347
req_wrap->object()->Set(env->async(), True(env->isolate()));
352348

353349
if (err)

src/stream_wrap.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
279279

280280

281281
int StreamWrap::DoShutdown(ShutdownWrap* req_wrap) {
282-
return uv_shutdown(&req_wrap->req_, stream(), AfterShutdown);
282+
int err;
283+
err = uv_shutdown(&req_wrap->req_, stream(), AfterShutdown);
284+
req_wrap->Dispatched();
285+
return err;
283286
}
284287

285288

@@ -353,6 +356,7 @@ int StreamWrap::DoWrite(WriteWrap* w,
353356
}
354357
}
355358

359+
w->Dispatched();
356360
UpdateWriteQueueSize();
357361

358362
return r;

src/tls_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ void TLSWrap::EncOut() {
309309
for (size_t i = 0; i < count; i++)
310310
buf[i] = uv_buf_init(data[i], size[i]);
311311
int err = stream_->DoWrite(write_req, buf, count, nullptr);
312-
write_req->Dispatched();
313312

314313
// Ignore errors, this should be already handled in js
315314
if (err) {
@@ -565,6 +564,7 @@ int TLSWrap::DoWrite(WriteWrap* w,
565564

566565
// Queue callback to execute it on next tick
567566
write_item_queue_.PushBack(new WriteItem(w));
567+
w->Dispatched();
568568

569569
// Write queued data
570570
if (empty) {

0 commit comments

Comments
 (0)