nicktelford opened a new pull request, #17713: URL: https://github.com/apache/kafka/pull/17713
The thread that evaluates the Gauge for the oldest-iterator-open-since-ms runs concurrently with threads that open/close Iterators (stream threads and interactive query threads). It's therefore possible that between evaluating `openIterators.isEmpty()` as `false` (because there's at least one open Iterator) and evaluating `openIterators.first()`, that the last open Iterator has been closed by a concurrent thread, causing `openIterators.first()` to throw a `NoSuchElementException`, which will break the Gauge and potentially the metrics reporting of the application. Unfortunately, `ConcurrentSkipListSet` doesn't provide an alternative to `first()` that retrieves the first element _without removing it_ or returns `null`. The best we can do is catch the `NoSuchElementException` and return a `null` instead. We keep the `openIterators.isEmpty()` check to avoid throwing an exception in the common-case that there are no open Iterators, because generating the stack trace when throwing the exception is fairly expensive. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
