diff --git a/platform/platform-impl/src/org/jetbrains/io/WebServer.java b/platform/platform-impl/src/org/jetbrains/io/WebServer.java index dbfef259ff6f..81f27334f0cf 100644 --- a/platform/platform-impl/src/org/jetbrains/io/WebServer.java +++ b/platform/platform-impl/src/org/jetbrains/io/WebServer.java @@ -65,30 +65,26 @@ public class WebServer { ServerBootstrap bootstrap = new ServerBootstrap(channelFactory); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setPipelineFactory(new ChannelPipelineFactoryImpl(pipelineConsumers, new DefaultHandler(openChannels))); - - // IDEA-91436 idea <121 binds to 127.0.0.1, but >=121 must be available not only from localhost - // but if we bind only to any local port (0.0.0.0), instance of idea <121 can bind to our ports and any request to us will be intercepted - // so, we bind to 127.0.0.1 and 0.0.0.0 - int port = bind(firstPort, portsCount, tryAnyPort, bootstrap); - if (port != -1) { - try { - openChannels.add(bootstrap.bind(new InetSocketAddress(port))); - } - catch (ChannelException e) { - LOG.error(e); - } - } - return port; + return bind(firstPort, portsCount, tryAnyPort, bootstrap); } + // IDEA-91436 idea <121 binds to 127.0.0.1, but >=121 must be available not only from localhost + // but if we bind only to any local port (0.0.0.0), instance of idea <121 can bind to our ports and any request to us will be intercepted + // so, we bind to 127.0.0.1 and 0.0.0.0 private int bind(int firstPort, int portsCount, boolean tryAnyPort, ServerBootstrap bootstrap) { for (int i = 0; i < portsCount; i++) { int port = firstPort + i; try { openChannels.add(bootstrap.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port))); + openChannels.add(bootstrap.bind(new InetSocketAddress(port))); return port; } catch (ChannelException e) { + if (!openChannels.isEmpty()) { + openChannels.close(); + openChannels.clear(); + } + if (portsCount == 1) { throw e; }