File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ v1.7.0 is a feature release. It is supported for all usage.
1212 client types (#399 ).
13134 . Fix for at-least-once guarantee not ensured in case a seek happens on one
1414partition and there are messages being fetched about other partitions (#393 ).
15-
15+ 5 . Avoid returning a negative lag in case there is no cached offset for
16+ the HWM (#406 ).
1617
1718# confluent-kafka-javascript 1.6.0
1819
Original file line number Diff line number Diff line change @@ -919,12 +919,18 @@ class Consumer {
919919 this . #logger. warn ( `Could not get watermark offsets for batch: ${ e } ` , this . #createConsumerBindingMessageMetadata( ) ) ;
920920 }
921921
922- if ( Number . isInteger ( watermarkOffsets . highOffset ) ) {
922+ /* Keep default values if it's not a real offset (OFFSET_INVALID: -1001). */
923+ if ( Number . isInteger ( watermarkOffsets . highOffset ) &&
924+ watermarkOffsets . highOffset >= 0 ) {
923925 highWatermark = watermarkOffsets . highOffset . toString ( ) ;
924926 /* While calculating lag, we subtract 1 from the high offset
925927 * for compatibility reasons with KafkaJS's API */
926928 offsetLag_ = ( watermarkOffsets . highOffset - 1 ) - messages [ messages . length - 1 ] . offset ;
927929 offsetLagLow_ = ( watermarkOffsets . highOffset - 1 ) - messages [ 0 ] . offset ;
930+
931+ /* In any case don't return a negative lag but a zero lag instead. */
932+ offsetLag_ = offsetLag_ > 0 ? offsetLag_ : 0 ;
933+ offsetLagLow_ = offsetLagLow_ > 0 ? offsetLagLow_ : 0 ;
928934 }
929935
930936 const messagesConverted = [ ] ;
You can’t perform that action at this time.
0 commit comments