@@ -1374,17 +1374,21 @@ class Consumer {
1374
1374
return ppc ;
1375
1375
}
1376
1376
1377
+ #notifyNonEmpty( ) {
1378
+ if ( this . #nonEmpty) {
1379
+ this . #nonEmpty. resolve ( ) ;
1380
+ this . #nonEmpty = null ;
1381
+ }
1382
+ if ( this . #messageCache)
1383
+ this . #messageCache. notifyAvailablePartitions ( ) ;
1384
+ }
1385
+
1377
1386
#queueNonEmptyCb( ) {
1378
1387
const nonEmptyAction = async ( ) => {
1379
1388
if ( this . #fetchInProgress)
1380
1389
await this . #fetchInProgress;
1381
1390
1382
- if ( this . #nonEmpty) {
1383
- this . #nonEmpty. resolve ( ) ;
1384
- this . #nonEmpty = null ;
1385
- }
1386
- if ( this . #messageCache)
1387
- this . #messageCache. notifyAvailablePartitions ( ) ;
1391
+ this . #notifyNonEmpty( ) ;
1388
1392
} ;
1389
1393
nonEmptyAction ( ) . catch ( ( e ) => {
1390
1394
this . #logger. error ( `Error in queueNonEmptyCb: ${ e } ` ,
@@ -1457,19 +1461,32 @@ class Consumer {
1457
1461
* @private
1458
1462
*/
1459
1463
async #cacheExpirationLoop( ) {
1464
+ const cacheExpirationInterval = BigInt ( this . #cacheExpirationTimeoutMs * 1e6 ) ;
1465
+ const maxFetchInterval = BigInt ( 1000 * 1e6 ) ;
1460
1466
while ( ! this . #workerTerminationScheduled. resolved ) {
1461
1467
let now = hrtime . bigint ( ) ;
1462
- const cacheExpiration = this . #lastFetchClockNs +
1463
- BigInt ( this . #cacheExpirationTimeoutMs * 1e6 ) ;
1468
+ const cacheExpirationTimeout = this . #lastFetchClockNs +
1469
+ cacheExpirationInterval ;
1470
+ const maxFetchTimeout = this . #lastFetchClockNs +
1471
+ maxFetchInterval ;
1464
1472
1465
- if ( now > cacheExpiration ) {
1473
+ if ( now > cacheExpirationTimeout ) {
1466
1474
this . #addPendingOperation( ( ) =>
1467
1475
this . #clearCacheAndResetPositions( ) ) ;
1468
1476
await this . #checkMaxPollIntervalNotExceeded( now ) ;
1469
1477
break ;
1470
1478
}
1479
+ if ( now > maxFetchTimeout ) {
1480
+ /* We need to continue fetching even when we're
1481
+ * not getting any messages, for example when all partitions are
1482
+ * paused. */
1483
+ this . #notifyNonEmpty( ) ;
1484
+ }
1485
+
1486
+ const awakeTime = maxFetchTimeout < cacheExpirationTimeout ?
1487
+ maxFetchTimeout : cacheExpirationTimeout ;
1471
1488
1472
- let interval = Number ( cacheExpiration - now ) / 1e6 ;
1489
+ let interval = Number ( awakeTime - now ) / 1e6 ;
1473
1490
if ( interval < 100 )
1474
1491
interval = 100 ;
1475
1492
await Timer . withTimeout ( interval , this . #maxPollIntervalRestart) ;
0 commit comments