Skip to content

Commit 2ab501a

Browse files
authored
Merge pull request #331 from AArnott/fix209
Block transmission of frames regarding terminated channels
2 parents fa4d9b9 + 65ce627 commit 2ab501a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Nerdbank.Streams.Tests/MultiplexingStreamTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,15 @@ public async Task PartialFrameSentWithoutExplicitFlush()
649649
[InlineData(false)]
650650
public async Task CancelChannelOfferBeforeAcceptance(bool cancelFirst)
651651
{
652-
// TODO: We need to test both the race condition where acceptance is sent before cancellation is received,
653-
// and the case where cancellation is received before we call AcceptChannelAsync.
654652
var cts = new CancellationTokenSource();
655653
var offer = this.mx1.OfferChannelAsync(string.Empty, cts.Token);
656654
cts.Cancel();
657655
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => offer).WithCancellation(this.TimeoutToken);
658656
Stream? acceptedStream = null;
659657
try
660658
{
659+
// We need to test both the race condition where acceptance is sent before cancellation is received,
660+
// and the case where cancellation is received before we call AcceptChannelAsync.
661661
if (cancelFirst)
662662
{
663663
// Increase the odds that cancellation will be processed before acceptance.

src/Nerdbank.Streams/MultiplexingStream.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,12 @@ private async Task SendFrameAsync(FrameHeader header, ReadOnlySequence<byte> pay
10861086
}
10871087
else
10881088
{
1089+
if (!this.openChannels.ContainsKey(qualifiedChannelId))
1090+
{
1091+
// Drop frames regarding channels that are not open.
1092+
return;
1093+
}
1094+
10891095
if (this.channelsPendingTermination.Contains(qualifiedChannelId))
10901096
{
10911097
// We shouldn't ever send a frame about a channel after we've transmitted a ChannelTermination frame for it.

0 commit comments

Comments
 (0)