IDEA-157421 Long shutdown due to built-in server

Reduce timeout to 10 seconds, log channels on timeout
This commit is contained in:
Vladimir Krivosheev
2016-06-14 13:47:56 +02:00
parent 9bc8da3fb1
commit f3b474fbd7
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package org.jetbrains.io;
import com.intellij.openapi.diagnostic.Logger;
import io.netty.channel.*;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.ChannelGroupFuture;
@@ -22,12 +23,15 @@ import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.ImmediateEventExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ChannelHandler.Sharable
public final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
private static final Logger LOG = Logger.getInstance(ChannelRegistrar.class);
private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE, true);
public boolean isEmpty() {
return openChannels.isEmpty();
@@ -64,8 +68,12 @@ public final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
Future<?> result;
try {
Object[] channels = openChannels.toArray(new Channel[]{});
ChannelGroupFuture groupFuture = openChannels.close();
groupFuture.awaitUninterruptibly(30, TimeUnit.SECONDS);
// server channels are closed in first turn, so, small timeout is relatively ok
if (!groupFuture.awaitUninterruptibly(10, TimeUnit.SECONDS)) {
LOG.warn("Cannot close all channels for 10 seconds, channels: " + Arrays.toString(channels));
}
result = groupFuture;
}
finally {