Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4202949

cannot bind ServerSocket to same port after closing it if exec'd process runs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • x86
    • windows_nt



      Name: gsC80088 Date: 01/13/99


      This is nearly the same as bug no. 4060907, but still reproducible in JDK1.2beta4!

      The attached program does the following:
      1. create a server socket on port 8003
      2. 'exec' Windows-Notepad
      3. close the server socket
      4. try to create the server socket again

      On (4.) I get the following error message:
      java.net.BindException: Address in use: bind

      If I do not exec Notepad or if I do a waitFor(Notepad), it works fine.

      The test program:
      --------------------------------------------------
      import java.io.*;
      import java.net.*;
      import java.util.*;

      public class TestBind
      {
          public static void main (String[] args)
          {
              ServerSocket mySocket;

              try
              {
                  Properties prop = System.getProperties();
                  String javaver = prop.getProperty("java.version");
                  if (javaver != null)
                      System.err.println("java version: "+javaver);
                  else
                      System.err.println("java.version: not found");
                  // create socket
                  System.err.println("create serverSocket");
                  mySocket = new ServerSocket(8003);

                  // exec notepad
                  String[] execcmd = new String[2];
                  execcmd[0] = "c:\\winnt\\system32\\notepad.exe";
                  execcmd[1] = "c:\\tmp\\test.html";


                  // execute the command
                  System.err.println("start exec");
                  Process notepad = Runtime.getRuntime().exec (execcmd);
                  //System.err.println("waiting for end of notepad");
                  //notepad.waitFor();

                  // close socket
                  System.err.println("close serverSocket");
                  mySocket.close();

                  // open socket again
                  System.err.println("open serverSocket again");
                  mySocket = new ServerSocket(8003);
                  
              }
              catch (IOException e)
              {
                  System.err.println(e);
              }
              /*catch (InterruptedException e)
              {
                  System.err.println(e);
              }*/

              System.exit(0);
          }
      }
      (Review ID: 39948)
      ======================================================================

            alanb Alan Bateman
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: