Uploaded image for project: 'XNIO'
  1. XNIO
  2. XNIO-385

Address already in use error is shown if a stream server is closed and created again quickly

XMLWordPrintable

    • Hide

      Code reproducer:

      public class Main {
          public static void main(String[] args) throws IOException {
              new Main().test();
          }
      
          private void test() throws IOException {
              final Xnio xnio = Xnio.getInstance("nio");
              OptionMap.Builder options = OptionMap.builder().set(Options.REUSE_ADDRESSES, true);
              final XnioWorker xnioWorker = xnio.createWorker(OptionMap.EMPTY);
      
              InetSocketAddress bindAddress = new InetSocketAddress(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), 20000);
      
              try {
                  while(true) {
                      final AcceptingChannel<StreamConnection> result = xnioWorker.createStreamConnectionServer(bindAddress, channel -> {
                      }, options.getMap());
      
                      IoUtils.safeClose(result);
                  }
              } finally {
                  xnioWorker.shutdown();
              }
          }
      }
      
      Show
      Code reproducer: public class Main { public static void main( String [] args) throws IOException { new Main().test(); } private void test() throws IOException { final Xnio xnio = Xnio.getInstance( "nio" ); OptionMap.Builder options = OptionMap.builder().set(Options.REUSE_ADDRESSES, true ); final XnioWorker xnioWorker = xnio.createWorker(OptionMap.EMPTY); InetSocketAddress bindAddress = new InetSocketAddress(Inet4Address.getByAddress( new byte []{127, 0, 0, 1}), 20000); try { while ( true ) { final AcceptingChannel<StreamConnection> result = xnioWorker.createStreamConnectionServer(bindAddress, channel -> { }, options.getMap()); IoUtils.safeClose(result); } } finally { xnioWorker.shutdown(); } } }
    • Undefined

      When an stream server is closed, the close method does not wait until the server keys are canceled with the resources released. This situation can lead to an "Address already in use" error when the same address and port are reused to quickly create a new server.

       

      The server keys are canceled but the close method does not wait until the resources are released.

            yborgess1@redhat.com Yeray Borges Santana
            yborgess1@redhat.com Yeray Borges Santana
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: