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

When closing an input stream obtained from an ftp URL connection, program hangs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.6, 1.2.2
    • core-libs
    • generic, x86
    • generic, windows_95



      Name: jn10789 Date: 11/20/98


      import java.net.*;
      import java.io.*;

      class ftphang
      {
              public static void main(String [] args)
      {
      InputStream is;
      URL url;

      try
      {
      // Create a URL from the pathname.
      url = new URL("ftp://ftp.kernel.org/pub/linux/kernel/v2.0/linux-2.0.35.tar.gz");
      is = url.openStream();
      System.out.println("Closing....");
      is.close();
      System.out.println("Closed");
      }
      catch(Exception e)
      {
      }
      }
      }
      When the above code is compiled and executed,
      the "closing..." message appears, the close method
      is invoked, and the program hangs. It is 100%
      reproducible.
      (Review ID: 35877)
      ======================================================================

      Name: dbT83986 Date: 08/15/99


      This program attempts to read the first 5 lines of a file
      over an ftp connection. The file is 425 lines long. The program
      hangs when an attempt to close the ftp input stream is made.
      Eventually the connection times out and the program exits.
      If the entire ftp stream content is read there is no delay
      when the connection is closed.

      bash-2.02$ cat tstFtp.java

      import java.io.BufferedReader;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.io.IOException;
      import java.net.URL;

      class tstFtp
      {
          public static void main(String[] args) throws Exception
          {
              URL ftp = new URL("ftp://user:xyz@racssv01/tmp/acct.dl");
              InputStream is = ftp.openStream();
              BufferedReader bis = new BufferedReader(new InputStreamReader(is));
              System.out.println("Begin header transfer");
              for(int l = 0; l < 5; l ++)
              {
                      String line = bis.readLine();
                      System.out.println(line);
              }
              System.out.println("End header transfer");
              bis.close();
              is.close();
              System.exit(0);
          }
      }

      bash-2.02$ java -version
      java version "1.2.2"
      HotSpot VM (1.0.1, mixed mode, build g)

      bash-2.02$ java tstFtp
      Begin header transfer
      BSC333 13 DIGIT ACCT 08/13/99 08/12/99 RACS13AC 28344 08/13/99


      SHA0000113CAD, ,TEST SHA IN PROD SPEC ,52V,+00000000000000000,+000000000
      00000000,+00000000000000000,+00000000000000000,A,+00000000,A,B,+00000000,A,C,+00
      000000,P,+00000000000000000+00000000000000000
      SHA0000113DEM, ,TEST SHA IN PROD SPEC ,52V,+00000000000000000,+000000000
      00000000,+00000000000000000,+00000000000000000,A,+00000000,A,B,+00000000,A,C,+00
      000000,P,+00000000000000000+00000000000000000
      SHA0000113EUR, ,SCOR DEMONSTRATION ,52V,+00000000000000000,+000000000
      00000000,+00000000000000000,+00000000000000000,A,+00000000,A,B,+00000000,A,C,+00
      000000,P,+00000000000000000+00000000000000000
      SHA0000113GBP, ,TEST SHA IN PROD SPEC ,52V,+00000000000000000,+000000000
      00000000,+00000000000000000,+00000000000000000,A,+00000000,A,B,+00000000,A,C,+00
      000000,P,+00000000000000000+00000000000000000
      End header transfer
      Full thread dump:

      "Signal Dispatcher" daemon prio=10 tid=0x815ef0 nid=0x6b waiting on monitor [0..0]

      "Finalizer" daemon prio=9 tid=0x814780 nid=0x15b waiting on monitor [0xe53f000..0xe53fdf0]
              at java.lang.Object.wait(Native Method)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:112)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
              at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:174)

      "Reference Handler" daemon prio=10 tid=0x814330 nid=0x60 waiting on monitor [0xe43f000..0xe43fdf0]
              at java.lang.Object.wait(Native Method)
              at java.lang.Object.wait(Object.java:424)
              at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:114)

      "main" prio=5 tid=0x7d1560 nid=0xfb initialized [0x12f000..0x12fe8c]
              at java.net.SocketInputStream.socketRead(Native Method)
              at java.net.SocketInputStream.read(SocketInputStream.java:90)
              at java.io.BufferedInputStream.fill(BufferedInputStream.java:190)
              at java.io.BufferedInputStream.read(BufferedInputStream.java:208)
              at sun.net.TransferProtocolClient.readServerResponse(TransferProtocolClient.java:56)
              at sun.net.ftp.FtpClient.readReply(FtpClient.java:176)
              at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:159)
              at sun.net.ftp.FtpClient.closeServer(FtpClient.java:148)
              at sun.net.ftp.FtpInputStream.close(FtpInputStream.java:49)
              at sun.net.www.MeteredStream.close(MeteredStream.java:95)
              at java.io.InputStreamReader.close(InputStreamReader.java:266)
              at java.io.BufferedReader.close(BufferedReader.java:442)
              at tstFtp.main(tstFtp.java:22)

      "VM Thread" prio=5 tid=0x8138e0 nid=0x16b runnable

      "VM Periodic Task Thread" prio=10 tid=0x815db0 nid=0x146 waiting on monitor
      (Review ID: 93918)
      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            jdn Jeffrey Nisewanger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: