@@ -87,14 +87,14 @@ internal void Validate()
87
87
88
88
switch ( ConsumerFilter )
89
89
{
90
- case { PostFilter : null } :
90
+ case { PostFilter : null } :
91
91
throw new ArgumentException ( "PostFilter must be provided when Filter is set" ) ;
92
- case { Values . Count : 0 } :
92
+ case { Values . Count : 0 } :
93
93
throw new ArgumentException ( "Values must be provided when Filter is set" ) ;
94
94
}
95
95
}
96
96
97
- internal bool IsFiltering => ConsumerFilter is { Values . Count : > 0 } ;
97
+ internal bool IsFiltering => ConsumerFilter is { Values . Count : > 0 } ;
98
98
99
99
// it is needed to be able to add the subscriptions arguments
100
100
// see consumerProperties["super-stream"] = SuperStream;
@@ -177,6 +177,7 @@ protected override string GetStream()
177
177
{
178
178
return _config . Stream ;
179
179
}
180
+
180
181
public async Task StoreOffset ( ulong offset )
181
182
{
182
183
await _client . StoreOffset ( _config . Reference , _config . Stream , offset ) . ConfigureAwait ( false ) ;
@@ -528,7 +529,8 @@ private async Task Init()
528
529
{
529
530
Logger ? . LogError (
530
531
"CRC32 does not match, server crc: {Crc}, local crc: {CrcCalculated}, {EntityInfo}, " +
531
- "Chunk Consumed {ChunkConsumed}" , deliver . Chunk . Crc , crcCalculated , DumpEntityConfiguration ( ) ,
532
+ "Chunk Consumed {ChunkConsumed}" , deliver . Chunk . Crc , crcCalculated ,
533
+ DumpEntityConfiguration ( ) ,
532
534
chunkConsumed ) ;
533
535
534
536
throw new CrcException (
@@ -537,7 +539,20 @@ private async Task Init()
537
539
}
538
540
}
539
541
540
- await _chunksBuffer . Writer . WriteAsync ( deliver . Chunk , Token ) . ConfigureAwait ( false ) ;
542
+ try
543
+ {
544
+ await _chunksBuffer . Writer . WriteAsync ( deliver . Chunk , Token ) . ConfigureAwait ( false ) ;
545
+ }
546
+ catch ( OperationCanceledException )
547
+ {
548
+ // The consumer is closing from the user but some chunks are still in the buffer
549
+ // simply skip the chunk since the Token.IsCancellationRequested is true
550
+ // the catch is needed to avoid to propagate the exception to the socket thread.
551
+ Logger ? . LogWarning (
552
+ "OperationCanceledException. {EntityInfo} has been closed while consuming messages. " +
553
+ "Token.IsCancellationRequested: {IsCancellationRequested}" ,
554
+ DumpEntityConfiguration ( ) , Token . IsCancellationRequested ) ;
555
+ }
541
556
} , async promotedAsActive =>
542
557
{
543
558
if ( _config . ConsumerUpdateListener != null )
@@ -628,11 +643,14 @@ protected override async Task<ResponseCode> DeleteEntityFromTheServer(bool ignor
628
643
}
629
644
630
645
return ResponseCode . Ok ;
631
-
632
646
}
633
647
634
648
public override async Task < ResponseCode > Close ( )
635
649
{
650
+ // when the consumer is closed we must be sure that the
651
+ // the subscription is completed to avoid problems with the connection
652
+ // It could happen when the closing is called just after the creation
653
+ await _completeSubscription . Task . ConfigureAwait ( false ) ;
636
654
return await Shutdown ( _config ) . ConfigureAwait ( false ) ;
637
655
}
638
656
0 commit comments