Hi!

The following problem exists in both JDK 1.1.6v5, and 1.1.7v1a. I've got a
glibc systems, and using the glibc versions of the JDK. My kernel is 2.0.34.

I'm pretty sure this is Linux specific, but I haven't been able to verify that
by trying it on another OS. But here goes.

Under certain circumstances which I will explain below, ServerSocket.accept()
results in a SocketException, with the message "Invalid argument", thrown in
PlainSocketImpl.java, line 379 (line 387 in JDK 1.1.6v5).

That method calls the native method socketAccept(SockImpl s) (I checked the JDK
enclosed Java source code). Now, what exacly is going wrong in
the underlaying implementaion, when it reports "invalid argument"? It sounds to
me like the native implementation passes some weird argument to listen() or
something similar. That, I think, would indicate a JDK bug.

Here's the scenario in which this happens:

I have a server that, among other things, goes into a loop, accepting clients
with ServerSocket.accept() (what else?) and lets another thread do its thing
with the returned Socket.

I also have a client that, among other things, connects to the server, with
a "... new Socket(hostname, 800)" call.

All is fine, and it works. I now kill the server, and the client will detect
the disconnected state of the Socket by the -1 returned by InputStrea.read(),
and will reconnect as follows, plus some waiting and exception handling of
course:

sock.close(); // Close client's end of the socket
sock = new Socket(hostname, 800); // IOException: Connection refused

Here's where the problem comes in. The client's connection attempt will fail. On
the client side, an IOException with the message "Connection refused" is thrown.
On the Server side, ServerSocket.accept() has now resulted in the mysterious
SocketException mentioned above.

Onte last note: The client attempt to connect to the server every 10 seconds.
If I make the server repeatedly try to call .accept() again, disregarding the
exceptions, a handfull of those calls will result in the same SocketException.
Then it will stop throwing them and start blocking again - until the clients
attempts another reconnect. 

It all works perfectly if I shut down the client, start it up again and
reconnect. No problem. It's only when the client is trying to reconnect after
an unexpected disconnect that the problem occurrs.

I am unable to figure out what I am doing wrong. Frankly, I don't have a clue.

1) Could this be a JDK bug?
2) Does anyone know how I might fix it? (if it's not Linux related, I guess
that should go off the mailinglist)

Thanks!

/ Peter Schuller
----------------
E-Mail: [EMAIL PROTECTED]
Web: http://hem.passagen.se/petersch

Reply via email to