57
57
import org .apache .hc .core5 .http .ProtocolException ;
58
58
import org .apache .hc .core5 .http .ProtocolVersion ;
59
59
import org .apache .hc .core5 .http .RequestNotExecutedException ;
60
+ import org .apache .hc .core5 .http .StreamClosedException ;
60
61
import org .apache .hc .core5 .http .config .CharCodingConfig ;
61
62
import org .apache .hc .core5 .http .impl .BasicEndpointDetails ;
62
63
import org .apache .hc .core5 .http .impl .BasicHttpConnectionMetrics ;
@@ -528,7 +529,11 @@ public final void onOutput() throws HttpException, IOException {
528
529
if (connState .compareTo (ConnectionHandshake .SHUTDOWN ) >= 0 ) {
529
530
if (!streamMap .isEmpty ()) {
530
531
for (final H2Stream stream : streamMap .values ()) {
531
- stream .releaseResources ();
532
+ if (stream .isLocalClosed () && stream .isRemoteClosed ()) {
533
+ stream .releaseResources ();
534
+ } else {
535
+ stream .fail (new ConnectionClosedException ());
536
+ }
532
537
}
533
538
streamMap .clear ();
534
539
}
@@ -575,7 +580,11 @@ public final void onDisconnect() {
575
580
for (final Iterator <Map .Entry <Integer , H2Stream >> it = streamMap .entrySet ().iterator (); it .hasNext (); ) {
576
581
final Map .Entry <Integer , H2Stream > entry = it .next ();
577
582
final H2Stream stream = entry .getValue ();
578
- stream .cancel ();
583
+ if (stream .isLocalClosed () && stream .isRemoteClosed ()) {
584
+ stream .releaseResources ();
585
+ } else {
586
+ stream .fail (new ConnectionClosedException ());
587
+ }
579
588
}
580
589
CommandSupport .cancelCommands (ioSession );
581
590
}
@@ -592,7 +601,11 @@ private void processPendingCommands() throws IOException, HttpException {
592
601
for (final Iterator <Map .Entry <Integer , H2Stream >> it = streamMap .entrySet ().iterator (); it .hasNext (); ) {
593
602
final Map .Entry <Integer , H2Stream > entry = it .next ();
594
603
final H2Stream stream = entry .getValue ();
595
- stream .cancel ();
604
+ if (stream .isLocalClosed () && stream .isRemoteClosed ()) {
605
+ stream .releaseResources ();
606
+ } else {
607
+ stream .fail (new ConnectionClosedException ());
608
+ }
596
609
}
597
610
streamMap .clear ();
598
611
connState = ConnectionHandshake .SHUTDOWN ;
@@ -982,7 +995,7 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
982
995
final int activeStreamId = entry .getKey ();
983
996
if (!idGenerator .isSameSide (activeStreamId ) && activeStreamId > processedLocalStreamId ) {
984
997
final H2Stream stream = entry .getValue ();
985
- stream .cancel ( );
998
+ stream .fail ( new RequestNotExecutedException () );
986
999
it .remove ();
987
1000
}
988
1001
}
@@ -1702,14 +1715,10 @@ HandlerFactory<AsyncPushConsumer> getPushHandlerFactory() {
1702
1715
return handler .getPushHandlerFactory ();
1703
1716
}
1704
1717
1705
- void cancel () {
1706
- fail (new RequestNotExecutedException ());
1707
- }
1708
-
1709
1718
boolean abort () {
1710
1719
final boolean cancelled = channel .cancel ();
1711
1720
if (released .compareAndSet (false , true )) {
1712
- handler .failed (new RequestNotExecutedException ());
1721
+ handler .failed (new StreamClosedException ());
1713
1722
handler .releaseResources ();
1714
1723
}
1715
1724
return cancelled ;
0 commit comments