Skip to content

Commit 45c3f5d

Browse files
committed
Handle Kafka and executor timeouts the same
1 parent 90bf7a7 commit 45c3f5d

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaUnboundedReader.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.NoSuchElementException;
3131
import java.util.Optional;
3232
import java.util.Set;
33+
import java.util.concurrent.ExecutionException;
3334
import java.util.concurrent.ExecutorService;
3435
import java.util.concurrent.Executors;
3536
import java.util.concurrent.Future;
@@ -114,17 +115,22 @@ public boolean start() throws IOException {
114115
try {
115116
Duration timeout = resolveDefaultApiTimeout(spec);
116117
future.get(timeout.getMillis(), TimeUnit.MILLISECONDS);
117-
} catch (TimeoutException e) {
118-
consumer.wakeup(); // This unblocks consumer stuck on network I/O.
119-
// Likely reason : Kafka servers are configured to advertise internal ips, but
120-
// those ips are not accessible from workers outside.
121-
String msg =
122-
String.format(
123-
"%s: Timeout while initializing partition '%s'. "
124-
+ "Kafka client may not be able to connect to servers.",
125-
this, pState.topicPartition);
126-
LOG.error("{}", msg);
127-
throw new IOException(msg);
118+
} catch (TimeoutException | ExecutionException e) {
119+
if (e instanceof TimeoutException
120+
|| e.getCause() instanceof org.apache.kafka.common.errors.TimeoutException) {
121+
// TODO: Find out if manually waking up was only relevant for legacy Kafka clients.
122+
consumer.wakeup(); // This unblocks consumer stuck on network I/O.
123+
// Likely reason : Kafka servers are configured to advertise internal ips, but
124+
// those ips are not accessible from workers outside.
125+
String msg =
126+
String.format(
127+
"%s: Timeout while initializing partition '%s'. "
128+
+ "Kafka client may not be able to connect to servers.",
129+
this, pState.topicPartition);
130+
LOG.error("{}", msg);
131+
throw new IOException(msg);
132+
}
133+
throw new IOException(e);
128134
} catch (Exception e) {
129135
throw new IOException(e);
130136
}

0 commit comments

Comments
 (0)