@@ -201,7 +201,8 @@ private enum AcknowledgementMode {
201
201
private final SubscriptionState subscriptions ;
202
202
private final ConsumerMetadata metadata ;
203
203
private final Metrics metrics ;
204
- private final long defaultApiTimeoutMs ;
204
+ private final int requestTimeoutMs ;
205
+ private final int defaultApiTimeoutMs ;
205
206
private volatile boolean closed = false ;
206
207
// Init value is needed to avoid NPE in case of exception raised in the constructor
207
208
private Optional <ClientTelemetryReporter > clientTelemetryReporter = Optional .empty ();
@@ -250,6 +251,7 @@ private enum AcknowledgementMode {
250
251
this .log = logContext .logger (getClass ());
251
252
252
253
log .debug ("Initializing the Kafka share consumer" );
254
+ this .requestTimeoutMs = config .getInt (ConsumerConfig .REQUEST_TIMEOUT_MS_CONFIG );
253
255
this .defaultApiTimeoutMs = config .getInt (ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG );
254
256
this .time = time ;
255
257
List <MetricsReporter > reporters = CommonClientConfigs .metricsReporters (clientId , config );
@@ -369,6 +371,7 @@ private enum AcknowledgementMode {
369
371
this .currentFetch = ShareFetch .empty ();
370
372
this .subscriptions = subscriptions ;
371
373
this .metadata = metadata ;
374
+ this .requestTimeoutMs = config .getInt (ConsumerConfig .REQUEST_TIMEOUT_MS_CONFIG );
372
375
this .defaultApiTimeoutMs = config .getInt (ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG );
373
376
this .acknowledgementMode = initializeAcknowledgementMode (config , log );
374
377
this .fetchBuffer = new ShareFetchBuffer (logContext );
@@ -450,7 +453,8 @@ private enum AcknowledgementMode {
450
453
final Metrics metrics ,
451
454
final SubscriptionState subscriptions ,
452
455
final ConsumerMetadata metadata ,
453
- final long defaultApiTimeoutMs ,
456
+ final int requestTimeoutMs ,
457
+ final int defaultApiTimeoutMs ,
454
458
final String groupId ) {
455
459
this .log = logContext .logger (getClass ());
456
460
this .subscriptions = subscriptions ;
@@ -464,6 +468,7 @@ private enum AcknowledgementMode {
464
468
this .backgroundEventReaper = backgroundEventReaper ;
465
469
this .metrics = metrics ;
466
470
this .metadata = metadata ;
471
+ this .requestTimeoutMs = requestTimeoutMs ;
467
472
this .defaultApiTimeoutMs = defaultApiTimeoutMs ;
468
473
this .acknowledgementMode = initializeAcknowledgementMode (null , log );
469
474
this .deserializers = new Deserializers <>(keyDeserializer , valueDeserializer , metrics );
@@ -874,7 +879,7 @@ private void close(final Duration timeout, final boolean swallowException) {
874
879
// We are already closing with a timeout, don't allow wake-ups from here on.
875
880
wakeupTrigger .disableWakeups ();
876
881
877
- final Timer closeTimer = time . timer (timeout );
882
+ final Timer closeTimer = createTimerForCloseRequests (timeout );
878
883
clientTelemetryReporter .ifPresent (ClientTelemetryReporter ::initiateClose );
879
884
closeTimer .update ();
880
885
@@ -909,6 +914,12 @@ private void close(final Duration timeout, final boolean swallowException) {
909
914
}
910
915
}
911
916
917
+ private Timer createTimerForCloseRequests (Duration timeout ) {
918
+ // this.time could be null if an exception occurs in constructor prior to setting the this.time field
919
+ final Time time = (this .time == null ) ? Time .SYSTEM : this .time ;
920
+ return time .timer (Math .min (timeout .toMillis (), requestTimeoutMs ));
921
+ }
922
+
912
923
/**
913
924
* Prior to closing the network thread, we need to make sure the following operations happen in the right sequence:
914
925
* 1. commit pending acknowledgements and close any share sessions
0 commit comments