Call onClose listener in a finally block

This commit is contained in:
Simon Willnauer 2017-05-12 16:32:29 +02:00
parent 279a18a527
commit e8e2ccdcf5
1 changed files with 5 additions and 2 deletions

View File

@ -411,10 +411,13 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
@Override @Override
public synchronized void close() throws IOException { public synchronized void close() throws IOException {
if (closed.compareAndSet(false, true)) { if (closed.compareAndSet(false, true)) {
try {
closeChannels(Arrays.stream(channels).filter(Objects::nonNull).collect(Collectors.toList())); closeChannels(Arrays.stream(channels).filter(Objects::nonNull).collect(Collectors.toList()));
} finally {
onClose.accept(this); onClose.accept(this);
} }
} }
}
@Override @Override
public DiscoveryNode getNode() { public DiscoveryNode getNode() {