Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2420

stop() hangs when start() has failed due to a port clash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 2.3.14.Final, 2.2.33.Final
    • Core
    • None
    • Hide

      The problem can be reproduced with the following unit test:

      package com.example;
      
      import static org.assertj.core.api.Assertions.assertThatRuntimeException;
      
      import java.io.IOException;
      import java.net.BindException;
      import java.net.InetSocketAddress;
      import java.net.ServerSocket;
      
      import org.junit.jupiter.api.Test;
      
      import io.undertow.Undertow;
      
      class UndertowTests {
      	
      	@Test
      	void startWithPortClashOnSecondHttpListenerThrowsRuntimeException() throws IOException {
      		try (ServerSocket socket = new ServerSocket()) {
      			socket.bind(new InetSocketAddress("0.0.0.0", 0));
      			int clashPort = socket.getLocalPort();
      			Undertow undertow = Undertow.builder()
      					.addHttpListener(0, "0.0.0.0")
      					.addHttpListener(clashPort, "0.0.0.0").build();
      			try {
      				assertThatRuntimeException().isThrownBy(undertow::start).withCauseInstanceOf(BindException.class);
      			}
      			finally {
      				undertow.stop();
      			}
      		}
      	}
      	
      }
      

      When run with 2.3.14.Final, the test hangs in the call to stop(). When run with 2.3.13.Final, the test passes.
       

       

      Show
      The problem can be reproduced with the following unit test: package com.example; import static org.assertj.core.api.Assertions.assertThatRuntimeException; import java.io.IOException; import java.net.BindException; import java.net.InetSocketAddress; import java.net.ServerSocket; import org.junit.jupiter.api.Test; import io.undertow.Undertow; class UndertowTests { @Test void startWithPortClashOnSecondHttpListenerThrowsRuntimeException() throws IOException { try (ServerSocket socket = new ServerSocket()) { socket.bind( new InetSocketAddress( "0.0.0.0" , 0)); int clashPort = socket.getLocalPort(); Undertow undertow = Undertow.builder() .addHttpListener(0, "0.0.0.0" ) .addHttpListener(clashPort, "0.0.0.0" ).build(); try { assertThatRuntimeException().isThrownBy(undertow::start).withCauseInstanceOf(BindException.class); } finally { undertow.stop(); } } } } When run with 2.3.14.Final, the test hangs in the call to stop() . When run with 2.3.13.Final, the test passes.    

      There appears to be a regression in 2.3.14.Final. stop() processing hangs when start() of an Undertow instance with multiple HTTP listeners has failed due to a port clash. The stack trace of the hang is the following:

      "main" #1 prio=5 os_prio=31 cpu=579.71ms elapsed=10.66s tid=0x00007f950a008e00 nid=0x2103 waiting on condition  [0x0000700002d2c000]
         java.lang.Thread.State: WAITING (parking)
      	at jdk.internal.misc.Unsafe.park(java.base@17.0.11/Native Method)
      	at java.util.concurrent.locks.LockSupport.park(java.base@17.0.11/LockSupport.java:341)
      	at org.xnio.nio.WorkerThread$SelectNowTask.doWait(WorkerThread.java:915)
      	at org.xnio.nio.WorkerThread.cancelKey(WorkerThread.java:793)
      	at org.xnio.nio.NioHandle.cancelKey(NioHandle.java:91)
      	at org.xnio.nio.NioTcpServer.close(NioTcpServer.java:261)
      	at org.xnio.nio.QueuedNioTcpServer2.close(QueuedNioTcpServer2.java:126)
      	at org.xnio.IoUtils.safeClose(IoUtils.java:152)
      	at io.undertow.Undertow.stop(Undertow.java:262)
      	- locked <0x000000061e400680> (a io.undertow.Undertow)
      	at com.example.UndertowTests.startWithPortClashOnSecondHttpListenerThrowsRuntimeException(UndertowTests.java:28)
      

      The problem does not occur with 2.3.13.Final.

              rhn-cservice-bbaranow Bartosz Baranowski
              ankinson Andy Wilkinson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: