Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4755503
Votes 0
Synopsis thread are blocked on the socket.accept()(ServerSocket class) method
Category java:classes_net
Reported Against 1.3.1
Release Fixed
State 11-Closed, duplicate of 4344135, bug
Priority: 3-Medium
Related Bugs 4344135
Submit Date 30-SEP-2002
Description




FULL PRODUCT VERSION :
java version Client VM 1.3.1_02(b02)



FULL OPERATING SYSTEM VERSION :
Linux Suse 7.2

A DESCRIPTION OF THE PROBLEM :
@ In other environments when the socket is closed a
java.net.SocketException is
thrown by the socket.accept() method. This exception is
caught by the listener
threads, at which point it checks if it is marked as not
alive, in which case
it terminates graceffully.

The following simple program can be used to reproduce the
problem (see below) 

My understanding is that this bug qualifies as a JDK bug.
The JDK used for the test was:

Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

When using Java HotSpot(TM) client VM (build 1.4.0_01-b03,
mixed mode) the
problem does not reproduce.

When using the Classic VM the bug does not reproduce
either, as the
socket.accept() calls throws exception when the socket is
closed by another
thread.

I verified using:

Classic VM (build 1.3.1_02-b02, green threads, nojit)

This is a Linux and JDK1.3.1_02 specific bug.

Expected Result:

Main thread waits for 2s
Listener thread waiting for connection
java.net.SocketException: socket closed
        void java.net.PlainSocketImpl.socketAccept(java.net.SocketImpl)
        void java.net.PlainSocketImpl.accept(java.net.SocketImpl)
        void java.net.ServerSocket.implAccept(java.net.Socket)
        java.net.Socket java.net.ServerSocket.accept()
        void Test$Listener.run()
        void java.lang.Thread.run()
Exiting listener thread
Exiting main thread

Result on  Linux :

Thread hangs without being able to exit.
Control-C to kill it.


Thanks,

ps, Please contact   xxxxx@xxxxx   for bookkeeping purpose.
He is the  xxxxx  contact with Sun JDK and is having regular conf with Sun
technicians.




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create the Test.java using the source code attached
2. compiler it
3. run it.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Throw an SocketException and thread terminated.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Thread hangs

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.*;

public class Test {

 private ServerSocket sock_= null;

 private Listener listener= null;

 private Thread thread= null;

 private Test() {
  try {
  init();
  }
  catch(Exception e) {
  e.printStackTrace();
  }
 }

 private void init() throws Exception {
  listener= new Listener();
  sock_= new ServerSocket(4999);
  thread= new Thread(listener);
  thread.start();
 }

 public void closeSocketAndWaitForListenerThreadToExit() throws Exception {
  sock_.close();
  thread.join();
 }

 public static void main(String args[]) throws Exception {
  Test test= new Test();

  System.out.println("Main thread waits for 2s");
  Thread.sleep(2000);

  test.closeSocketAndWaitForListenerThreadToExit();

  System.out.println("Exiting main thread");
 }

 class Listener implements Runnable {

 public void run() {
  System.out.println("Listener thread waiting for connection");

  try {
  sock_.accept();
  }
  catch(Exception e) {
  e.printStackTrace();
  }

  System.out.println("Exiting listener thread");
 }

} 

} 

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Using Classic VM
(Review ID: 164313) 
======================================================================
Work Around
N/A
Evaluation
Already fixed in 1.4 - see 4344135. For 1.3.1 the workaround is set
J2SE_PREEMPTIVECLOSE to 1 prior to launching.
  xxxxx@xxxxx   2002-09-30
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang