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 @@ -986,6 +986,8 @@ function emitClose(self, error) {
986986}
987987
988988function finishSessionDestroy ( session , error ) {
989+ debugSessionObj ( session , 'finishSessionDestroy' ) ;
990+
989991 const socket = session [ kSocket ] ;
990992 if ( ! socket . destroyed )
991993 socket . destroy ( error ) ;
@@ -1354,16 +1356,12 @@ class Http2Session extends EventEmitter {
13541356 const handle = this [ kHandle ] ;
13551357
13561358 // 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 ) ;
13581361 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 {
13661363 finishSessionDestroy ( this , error ) ;
1364+ }
13671365 }
13681366
13691367 // Closing the session will:
Original file line number Diff line number Diff line change @@ -683,6 +683,13 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
683683
684684 flags_ |= SESSION_STATE_CLOSED;
685685
686+ // If we are writing we will get to make the callback in OnStreamAfterWrite.
687+ if ((flags_ & SESSION_STATE_WRITE_IN_PROGRESS) == 0 ) {
688+ Debug (this , " make done session callback" );
689+ HandleScope scope (env ()->isolate ());
690+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
691+ }
692+
686693 // If there are outstanding pings, those will need to be canceled, do
687694 // so on the next iteration of the event loop to avoid calling out into
688695 // javascript since this may be called during garbage collection.
@@ -1485,6 +1492,12 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
14851492 stream_->ReadStart ();
14861493 }
14871494
1495+ if ((flags_ & SESSION_STATE_CLOSED) != 0 ) {
1496+ HandleScope scope (env ()->isolate ());
1497+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
1498+ return ;
1499+ }
1500+
14881501 // If there is more incoming data queued up, consume it.
14891502 if (stream_buf_offset_ > 0 ) {
14901503 ConsumeHTTP2Data ();
You can’t perform that action at this time.
0 commit comments