Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Oct 1998 23:35:56 -0800
From:      Mahadevan Iyer <iyer@internetdevices.com>
To:        java-port@FreeBSD.ORG, freebsd-java@FreeBSD.ORG, saurabh@internetdevices.com, iyer@internetdevices.com, namit@internetdevices.com
Subject:   Possible Bug in JVM socket code on FreeBSD, java.net.Socket
Message-ID:  <36381ADB.DCCDAB3D@internetdevices.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------6512B0160517B8DDA22B1BB9
Content-Type: multipart/alternative; boundary="------------AC16728A372C0B33E606B4E6"


--------------AC16728A372C0B33E606B4E6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have a simple Server and Client pair
Server listens for connections on fixed port
Clients connect to the server on the port

The Client opens N connections to the server and keeps them open
The Server sends data on each of these connections
The Client listens for data on each of these connections in a single
thread

N > 250 causes the Client to dump core

java -version

     java version "1.1.6"

I do get this warning when I try to run the interpreter

     /usr/libexec/ld.so: warning: /usr/lib/libc.so.3.0: minor
     version 0 older than expected 1, using it anyway
     /usr/libexec/ld.so: warning: /usr/lib/libc.so.3.0: minor
     version 0 older than expected 1, using it anyway

     Is this related to the problem described above

FreeBSD Version

     > uname -a
     FreeBSD fbsd.abhiweb.com 2.2-STABLE FreeBSD 2.2-STABLE #0: Fri
     Aug 15 08:06:41

------------------

Connection # : 249
Connection # : 250
SIGSEGV   11*  segmentation violation

Full thread dump:
    "Finalizer thread" (TID:0x8414208, sys_thread_t:0x9218efc, state:CW)
prio=1
    "Async Garbage Collector" (TID:0x8414250, sys_thread_t:0x91f7efc,
state:R) prio=1
    "Idle thread" (TID:0x8414298, sys_thread_t:0x91d6efc, state:R)
prio=0
    "Clock" (TID:0x8414088, sys_thread_t:0x91b5efc, state:CW) prio=12
    "main" (TID:0x84140b0, sys_thread_t:0x4e00, state:R) prio=5 *current
thread*
 java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:290)
 java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:132)
 java.net.PlainSocketImpl.connect(PlainSocketImpl.java:119)
 java.net.Socket.<init>(Socket.java:229)
 java.net.Socket.<init>(Socket.java:97)
 TClient.<init>(TClient.java:19)
 TClient.main(TClient.java:68)
Monitor Cache Dump:
    <unknown key> (0x91f7efc): owner "Async Garbage Collector"
(0x91f7efc, 1 entry)
Registered Monitor Dump:
    Thread queue lock: <unowned>
    Name and type hash table lock: <unowned>
    String intern lock: <unowned>
    JNI pinning lock: <unowned>
    JNI global reference lock: <unowned>
    BinClass lock: <unowned>
    Class loading lock: <unowned>
    Java stack lock: <unowned>
    Code rewrite lock: <unowned>
    Heap lock: <unowned>
    Has finalization queue lock: <unowned>
    Finalize me queue lock: <unowned>
 Waiting to be notified:
     "Finalizer thread" (0x9218efc)
    Monitor IO lock: <unowned>
    Child death monitor: <unowned>
    Event monitor: <unowned>
    I/O monitor: <unowned>
    Alarm monitor: <unowned>
 Waiting to be notified:
     "Clock" (0x91b5efc)
    _malloc: <unowned>
    Monitor registry: owner "main" (0x4e00, 1 entry)
Thread Alarm Q:
Abort trap (core dumped)

-----------------------------

I have included the 2 files TServer.java and TClient.java

To reproduce

     compile java files using jdk1.1.6

     su to root so that you can open at least 1024 connections

     cd to directory with TServer.class and TClient.class

Server

     JAVA1.1.6HOME/bin/java TServer 5000

Client

     JAVA1.1.6HOME/bin/java TClient 1000

--------------AC16728A372C0B33E606B4E6
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
I&nbsp;have a simple Server and Client pair
<BR>Server listens for connections on fixed port
<BR>Clients connect to the server on the port

<P>The Client opens N&nbsp;connections to the server and keeps them open
<BR>The Server sends data on each of these connections
<BR>The Client listens for data on each of these connections in a single
thread

<P>N&nbsp;>&nbsp;250 causes the Client to dump core

<P>java -version
<BLOCKQUOTE>java version "1.1.6"</BLOCKQUOTE>
I&nbsp;do get this warning when I&nbsp;try to run the interpreter
<BLOCKQUOTE>/usr/libexec/ld.so: warning: /usr/lib/libc.so.3.0: minor version
0 older than expected 1, using it anyway
<BR>/usr/libexec/ld.so: warning: /usr/lib/libc.so.3.0: minor version 0
older than expected 1, using it anyway

<P>Is this related to the problem described above</BLOCKQUOTE>


<P>FreeBSD&nbsp;Version
<BLOCKQUOTE>> uname -a
<BR>FreeBSD fbsd.abhiweb.com 2.2-STABLE FreeBSD 2.2-STABLE #0: Fri Aug
15 08:06:41</BLOCKQUOTE>
------------------

<P>Connection # : 249
<BR>Connection # : 250
<BR>SIGSEGV&nbsp;&nbsp; 11*&nbsp; segmentation violation

<P>Full thread dump:
<BR>&nbsp;&nbsp;&nbsp; "Finalizer thread" (TID:0x8414208, sys_thread_t:0x9218efc,
state:CW) prio=1
<BR>&nbsp;&nbsp;&nbsp; "Async Garbage Collector" (TID:0x8414250, sys_thread_t:0x91f7efc,
state:R) prio=1
<BR>&nbsp;&nbsp;&nbsp; "Idle thread" (TID:0x8414298, sys_thread_t:0x91d6efc,
state:R) prio=0
<BR>&nbsp;&nbsp;&nbsp; "Clock" (TID:0x8414088, sys_thread_t:0x91b5efc,
state:CW) prio=12
<BR>&nbsp;&nbsp;&nbsp; "main" (TID:0x84140b0, sys_thread_t:0x4e00, state:R)
prio=5 *current thread*
<BR>&nbsp;java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:290)
<BR>&nbsp;java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:132)
<BR>&nbsp;java.net.PlainSocketImpl.connect(PlainSocketImpl.java:119)
<BR>&nbsp;java.net.Socket.&lt;init>(Socket.java:229)
<BR>&nbsp;java.net.Socket.&lt;init>(Socket.java:97)
<BR>&nbsp;TClient.&lt;init>(TClient.java:19)
<BR>&nbsp;TClient.main(TClient.java:68)
<BR>Monitor Cache Dump:
<BR>&nbsp;&nbsp;&nbsp; &lt;unknown key> (0x91f7efc): owner "Async Garbage
Collector" (0x91f7efc, 1 entry)
<BR>Registered Monitor Dump:
<BR>&nbsp;&nbsp;&nbsp; Thread queue lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Name and type hash table lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; String intern lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; JNI pinning lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; JNI global reference lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; BinClass lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Class loading lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Java stack lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Code rewrite lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Heap lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Has finalization queue lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Finalize me queue lock: &lt;unowned>
<BR>&nbsp;Waiting to be notified:
<BR>&nbsp;&nbsp;&nbsp;&nbsp; "Finalizer thread" (0x9218efc)
<BR>&nbsp;&nbsp;&nbsp; Monitor IO lock: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Child death monitor: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Event monitor: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; I/O monitor: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Alarm monitor: &lt;unowned>
<BR>&nbsp;Waiting to be notified:
<BR>&nbsp;&nbsp;&nbsp;&nbsp; "Clock" (0x91b5efc)
<BR>&nbsp;&nbsp;&nbsp; _malloc: &lt;unowned>
<BR>&nbsp;&nbsp;&nbsp; Monitor registry: owner "main" (0x4e00, 1 entry)
<BR>Thread Alarm Q:
<BR>Abort trap (core dumped)

<P>-----------------------------

<P>I&nbsp;have included the 2 files TServer.java and TClient.java

<P>To reproduce
<BLOCKQUOTE>compile java files using jdk1.1.6</BLOCKQUOTE>

<BLOCKQUOTE>su to root so that you can open at least 1024 connections</BLOCKQUOTE>

<BLOCKQUOTE>cd to directory with TServer.class and TClient.class</BLOCKQUOTE>
Server
<BLOCKQUOTE>JAVA1.1.6HOME/bin/java TServer 5000</BLOCKQUOTE>
Client
<BLOCKQUOTE>JAVA1.1.6HOME/bin/java TClient 1000</BLOCKQUOTE>
</HTML>

--------------AC16728A372C0B33E606B4E6--

--------------6512B0160517B8DDA22B1BB9
Content-Type: text/plain; charset=us-ascii; name="TServer.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="TServer.java"

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

class DataThread extends Thread {
  Vector _connections;
  public DataThread(Vector connections) {
    _connections = connections;
  }

  public void run() {
    int i = 0;
    String[] message = {
	"Hello",
	"how",
	"are",
	"you"
    };
    while(true) {
      i++;
      try {
        Thread.sleep(100);
	if(_connections.isEmpty())
	  continue;
        int index = i % _connections.size();
	Socket s = (Socket)_connections.elementAt(index);
	try {
	  s.getOutputStream().write(message[i % 4].getBytes());
	}
	catch(Exception e) {
	  System.out.println("Removing socket : " + String.valueOf(index));
          _connections.removeElementAt(index);
	}
	System.out.print('.');
      }
      catch(Exception e) {
	e.printStackTrace();
      }
    }
  }
}

public class TServer {

  ServerSocket _server;
  Vector _clients;

  public TServer(int port) throws Exception {
    _server = new ServerSocket(port);
    System.out.println("Listening on port : " + String.valueOf(port));

    _clients = new Vector(); 
    DataThread dt = new DataThread(_clients);
    dt.start();
    while(true) {
      try {
        Socket s = _server.accept();
	_clients.addElement(s);
	System.out.println("Accepted connection : " + String.valueOf(_clients.size()));
      }
      catch(Exception e) {
	System.out.println("Error Accepting connection : " + String.valueOf(_clients.size()));
	e.printStackTrace();
	break;
      } 
    }
  }

  public static void main(String[] args) throws Exception {
    if(args.length == 0) {
      System.out.println("Usage: java TServer <port>");
      System.exit(1);
    }

    int port = Integer.parseInt(args[0]);
    TServer server = new TServer(port);
  }
}



--------------6512B0160517B8DDA22B1BB9
Content-Type: text/plain; charset=us-ascii; name="TClient.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="TClient.java"

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

public class TClient {

  Vector _connections;

  public TClient(String host, int port, int max) throws Exception {
    _connections = new Vector();
    System.out.println("Initializing TClient");
    if(System.getProperty("DELAY") != null)
	System.out.println("Using DELAY");
    else
	System.out.println("NOT Using DELAY");
    long t1 = System.currentTimeMillis();
    while(_connections.size() < max) {
      try {
        Socket s = new Socket(host, port);
	System.out.println("Connection # : " + String.valueOf(_connections.size()));
        _connections.addElement(s);
	if(System.getProperty("DELAY") != null) {
	  System.out.println("DELAY");
	  Thread.sleep(10);
	}
      }
      catch(Exception e) {
	System.out.println("Error Connection # : " + String.valueOf(_connections.size()));
	e.printStackTrace();
	break;
      }
    }
    long t2 = System.currentTimeMillis();
    System.out.println("Average Connection time : " + 
				String.valueOf( (t2 - t1)/max));
  }

  public void poll() {
    try {
      while(true) {
        for(int i = 0; i < _connections.size(); i++) {
    	  Socket  s = (Socket)(_connections.elementAt(i));
          if(s.getInputStream().available() > 0) {
 	    byte[] data = new byte[s.getInputStream().available()];
	    s.getInputStream().read(data);
	    String message = new String(data);
	    // System.out.print(String.valueOf(i) + " : " + message + "; ");
	    System.out.print(String.valueOf(i) +  "; ");
	  }
        }
        Thread.sleep(100);
        System.out.print('.');
      }
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) throws Exception {
    if(args.length < 3) {
      System.out.println("Usage: java TClient <server> <port> <maxconnections>");
      System.exit(1);
    }
   
    int port = Integer.parseInt(args[1]);
    int max = Integer.parseInt(args[2]);
    TClient client = new TClient(args[0], port, max);
    client.poll();
  }
}

--------------6512B0160517B8DDA22B1BB9--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?36381ADB.DCCDAB3D>