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 @@ -986,6 +986,8 @@ function emitClose(self, error) {
986
986
}
987
987
988
988
function finishSessionDestroy ( session , error ) {
989
+ debugSessionObj ( session , 'finishSessionDestroy' ) ;
990
+
989
991
const socket = session [ kSocket ] ;
990
992
if ( ! socket . destroyed )
991
993
socket . destroy ( error ) ;
@@ -1354,16 +1356,12 @@ class Http2Session extends EventEmitter {
1354
1356
const handle = this [ kHandle ] ;
1355
1357
1356
1358
// Destroy the handle if it exists at this point
1357
- if ( handle !== undefined )
1359
+ if ( handle !== undefined ) {
1360
+ handle . ondone = finishSessionDestroy . bind ( null , this , error ) ;
1358
1361
handle . destroy ( code , socket . destroyed ) ;
1359
-
1360
- // If the socket is alive, use setImmediate to destroy the session on the
1361
- // next iteration of the event loop in order to give data time to transmit.
1362
- // Otherwise, destroy immediately.
1363
- if ( ! socket . destroyed )
1364
- setImmediate ( finishSessionDestroy , this , error ) ;
1365
- else
1362
+ } else {
1366
1363
finishSessionDestroy ( this , error ) ;
1364
+ }
1367
1365
}
1368
1366
1369
1367
// Closing the session will:
Original file line number Diff line number Diff line change @@ -700,6 +700,13 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
700
700
701
701
flags_ |= SESSION_STATE_CLOSED;
702
702
703
+ // If we are writing we will get to make the callback in OnStreamAfterWrite.
704
+ if ((flags_ & SESSION_STATE_WRITE_IN_PROGRESS) == 0 ) {
705
+ Debug (this , " make done session callback" );
706
+ HandleScope scope (env ()->isolate ());
707
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
708
+ }
709
+
703
710
// If there are outstanding pings, those will need to be canceled, do
704
711
// so on the next iteration of the event loop to avoid calling out into
705
712
// javascript since this may be called during garbage collection.
@@ -1502,6 +1509,12 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
1502
1509
stream_->ReadStart ();
1503
1510
}
1504
1511
1512
+ if ((flags_ & SESSION_STATE_CLOSED) != 0 ) {
1513
+ HandleScope scope (env ()->isolate ());
1514
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
1515
+ return ;
1516
+ }
1517
+
1505
1518
// If there is more incoming data queued up, consume it.
1506
1519
if (stream_buf_offset_ > 0 ) {
1507
1520
ConsumeHTTP2Data ();
You can’t perform that action at this time.
0 commit comments