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 @@ -1022,6 +1022,8 @@ function emitClose(self, error) {
1022
1022
}
1023
1023
1024
1024
function finishSessionDestroy ( session , error ) {
1025
+ debugSessionObj ( session , 'finishSessionDestroy' ) ;
1026
+
1025
1027
const socket = session [ kSocket ] ;
1026
1028
if ( ! socket . destroyed )
1027
1029
socket . destroy ( error ) ;
@@ -1390,16 +1392,12 @@ class Http2Session extends EventEmitter {
1390
1392
const handle = this [ kHandle ] ;
1391
1393
1392
1394
// Destroy the handle if it exists at this point
1393
- if ( handle !== undefined )
1395
+ if ( handle !== undefined ) {
1396
+ handle . ondone = finishSessionDestroy . bind ( null , this , error ) ;
1394
1397
handle . destroy ( code , socket . destroyed ) ;
1395
-
1396
- // If the socket is alive, use setImmediate to destroy the session on the
1397
- // next iteration of the event loop in order to give data time to transmit.
1398
- // Otherwise, destroy immediately.
1399
- if ( ! socket . destroyed )
1400
- setImmediate ( finishSessionDestroy , this , error ) ;
1401
- else
1398
+ } else {
1402
1399
finishSessionDestroy ( this , error ) ;
1400
+ }
1403
1401
}
1404
1402
1405
1403
// Closing the session will:
Original file line number Diff line number Diff line change @@ -693,6 +693,13 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
693
693
694
694
flags_ |= SESSION_STATE_CLOSED;
695
695
696
+ // If we are writing we will get to make the callback in OnStreamAfterWrite.
697
+ if ((flags_ & SESSION_STATE_WRITE_IN_PROGRESS) == 0 ) {
698
+ Debug (this , " make done session callback" );
699
+ HandleScope scope (env ()->isolate ());
700
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
701
+ }
702
+
696
703
// If there are outstanding pings, those will need to be canceled, do
697
704
// so on the next iteration of the event loop to avoid calling out into
698
705
// javascript since this may be called during garbage collection.
@@ -1530,6 +1537,12 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
1530
1537
stream_->ReadStart ();
1531
1538
}
1532
1539
1540
+ if ((flags_ & SESSION_STATE_CLOSED) != 0 ) {
1541
+ HandleScope scope (env ()->isolate ());
1542
+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
1543
+ return ;
1544
+ }
1545
+
1533
1546
// If there is more incoming data queued up, consume it.
1534
1547
if (stream_buf_offset_ > 0 ) {
1535
1548
ConsumeHTTP2Data ();
You can’t perform that action at this time.
0 commit comments