File tree 2 files changed +19
-8
lines changed
2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -1010,6 +1010,8 @@ function emitClose(self, error) {
1010
1010
}
1011
1011
1012
1012
function finishSessionDestroy ( session , error ) {
1013
+ debugSessionObj ( session , 'finishSessionDestroy' ) ;
1014
+
1013
1015
const socket = session [ kSocket ] ;
1014
1016
if ( ! socket . destroyed )
1015
1017
socket . destroy ( error ) ;
@@ -1378,16 +1380,12 @@ class Http2Session extends EventEmitter {
1378
1380
const handle = this [ kHandle ] ;
1379
1381
1380
1382
// Destroy the handle if it exists at this point
1381
- if ( handle !== undefined )
1383
+ if ( handle !== undefined ) {
1384
+ handle . ondone = finishSessionDestroy . bind ( null , this , error ) ;
1382
1385
handle . destroy ( code , socket . destroyed ) ;
1383
-
1384
- // If the socket is alive, use setImmediate to destroy the session on the
1385
- // next iteration of the event loop in order to give data time to transmit.
1386
- // Otherwise, destroy immediately.
1387
- if ( ! socket . destroyed )
1388
- setImmediate ( finishSessionDestroy , this , error ) ;
1389
- else
1386
+ } else {
1390
1387
finishSessionDestroy ( this , error ) ;
1388
+ }
1391
1389
}
1392
1390
1393
1391
// Closing the session will:
Original file line number Diff line number Diff line change @@ -689,6 +689,13 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
689
689
690
690
flags_ |= SESSION_STATE_CLOSED;
691
691
692
+ // If we are writing we will get to make the callback in OnStreamAfterWrite.
693
+ if ((flags_ & SESSION_STATE_WRITE_IN_PROGRESS) == 0 ) {
694
+ Debug (this , " make done session callback" );
695
+ HandleScope scope (env ()->isolate ());
696
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
697
+ }
698
+
692
699
// If there are outstanding pings, those will need to be canceled, do
693
700
// so on the next iteration of the event loop to avoid calling out into
694
701
// javascript since this may be called during garbage collection.
@@ -1526,6 +1533,12 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
1526
1533
stream_->ReadStart ();
1527
1534
}
1528
1535
1536
+ if ((flags_ & SESSION_STATE_CLOSED) != 0 ) {
1537
+ HandleScope scope (env ()->isolate ());
1538
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
1539
+ return ;
1540
+ }
1541
+
1529
1542
// If there is more incoming data queued up, consume it.
1530
1543
if (stream_buf_offset_ > 0 ) {
1531
1544
ConsumeHTTP2Data ();
You can’t perform that action at this time.
0 commit comments