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 @@ -700,6 +700,13 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
700700
701701 flags_ |= SESSION_STATE_CLOSED;
702702
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+
703710 // If there are outstanding pings, those will need to be canceled, do
704711 // so on the next iteration of the event loop to avoid calling out into
705712 // javascript since this may be called during garbage collection.
@@ -1502,6 +1509,12 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
15021509 stream_->ReadStart ();
15031510 }
15041511
1512+ if ((flags_ & SESSION_STATE_CLOSED) != 0 ) {
1513+ HandleScope scope (env ()->isolate ());
1514+ MakeCallback (env ()->ondone_string (), 0 , nullptr );
1515+ return ;
1516+ }
1517+
15051518 // If there is more incoming data queued up, consume it.
15061519 if (stream_buf_offset_ > 0 ) {
15071520 ConsumeHTTP2Data ();
You can’t perform that action at this time.
0 commit comments