Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConsumeService: fix client close() causing ConcurrentModificationExeption #393

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public ConsumeService(String name,
}
}, name + " consume-service");
_consumeThread.setDaemon(true);
_consumeThread.setUncaughtExceptionHandler((t, e) -> {
LOG.error(name + "/ConsumeService error", e);
});
});

// In a blocking fashion, waits for this topicPartitionFuture to complete, and then returns its result.
Expand Down Expand Up @@ -211,6 +214,9 @@ public void onComplete(Map<TopicPartition, OffsetAndMetadata> topicPartitionOffs
}
}
/* end of consume() while loop */
LOG.info("{}/ConsumeService/Consumer closing.", _name);
_baseConsumer.close();
LOG.info("{}/ConsumeService/Consumer stopped.", _name);
}

Metrics metrics() {
Expand Down Expand Up @@ -242,17 +248,18 @@ public synchronized void start() {
@Override
public synchronized void stop() {
if (_running.compareAndSet(true, false)) {
try {
_baseConsumer.close();
} catch (Exception e) {
LOG.warn(_name + "/ConsumeService while trying to close consumer.", e);
}
LOG.info("{}/ConsumeService stopped.", _name);
LOG.info("{}/ConsumeService stopping.", _name);
}
}

@Override
public void awaitShutdown(long timeout, TimeUnit unit) {
LOG.info("{}/ConsumeService shutdown awaiting…", _name);
try {
_consumeThread.join(unit.toMillis(timeout));
} catch (InterruptedException e) {
LOG.error(_name + "/ConsumeService interrupted", e);
lmr3796 marked this conversation as resolved.
Show resolved Hide resolved
}
LOG.info("{}/ConsumeService shutdown completed.", _name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void run() {
Thread.sleep(100);

consumeService.stop();
thread.join(500);
thread.join(5000);

Assert.assertFalse(thread.isAlive());
Assert.assertEquals(error.get(), null);
Expand Down