magibney commented on code in PR #834: URL: https://github.com/apache/solr/pull/834#discussion_r864284919
########## solr/core/src/java/org/apache/solr/cloud/ZkController.java: ########## @@ -2753,18 +2757,25 @@ private boolean fireEventListeners(String zkDir) { if (listeners != null && !listeners.isEmpty()) { final Set<Runnable> listenersCopy = new HashSet<>(listeners); // run these in a separate thread because this can be long running + final AtomicReference<Future<?>> listenerFuture = new AtomicReference<>(); Runnable work = () -> { - log.debug("Running listeners for {}", zkDir); - for (final Runnable listener : listenersCopy) { - try { - listener.run(); - } catch (RuntimeException e) { - log.warn("listener throws error", e); + try { + log.debug("Running listeners for {}", zkDir); + for (final Runnable listener : listenersCopy) { + try { + listener.run(); + } catch (RuntimeException e) { + log.warn("listener throws error", e); + } } + } finally { + futures.remove(listenerFuture.getAndSet(null)); } }; - cc.getCoreZkRegisterExecutorService().submit(work); + Future<?> future = cc.getCoreZkRegisterExecutorService().submit(work); + listenerFuture.set(future); + futures.add(future); Review Comment: Actually, looks like `ConcurrentHashMap.newKeySet()` would throw an NPE on `set.remove(null)`, which would be less subtle. In any case I think this would be addressed by `FutureTask` or some other suitable change. -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org