File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -1017,6 +1017,8 @@ function emitClose(self, error) {
1017
1017
}
1018
1018
1019
1019
function finishSessionDestroy ( session , error ) {
1020
+ debugSessionObj ( session , 'finishSessionDestroy' ) ;
1021
+
1020
1022
const socket = session [ kSocket ] ;
1021
1023
if ( ! socket . destroyed )
1022
1024
socket . destroy ( error ) ;
@@ -1385,16 +1387,12 @@ class Http2Session extends EventEmitter {
1385
1387
const handle = this [ kHandle ] ;
1386
1388
1387
1389
// Destroy the handle if it exists at this point
1388
- if ( handle !== undefined )
1390
+ if ( handle !== undefined ) {
1391
+ handle . ondone = finishSessionDestroy . bind ( null , this , error ) ;
1389
1392
handle . destroy ( code , socket . destroyed ) ;
1390
-
1391
- // If the socket is alive, use setImmediate to destroy the session on the
1392
- // next iteration of the event loop in order to give data time to transmit.
1393
- // Otherwise, destroy immediately.
1394
- if ( ! socket . destroyed )
1395
- setImmediate ( finishSessionDestroy , this , error ) ;
1396
- else
1393
+ } else {
1397
1394
finishSessionDestroy ( this , error ) ;
1395
+ }
1398
1396
}
1399
1397
1400
1398
// 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