SocketServer accept() fails to work (Linux)

From: Janusz (januszstu_at_cut-out-spam.pl)
Date: 05/31/04


Date: Mon, 31 May 2004 16:49:35 +0200

Hello,

I have the following problem with my server appllication:

This is typical server implemented in Java, using ServerSocket object,
waiting for client to connenct on ServerSocket.accept()
method. When the client connects (socket is received from accept() method)
it is handled by the server in separate thread.
The server writes the received data to the file and then closes the socket.
The problem:
the server handles about 20 connections daily, receiving about 100kB - 1MB
of data in each connection.
However after a few days the server fails to work,
the server waits on ServerSocket.accept() (as usually), however the clients
fail to connect to the server, but the server does not see
that any client tried to connect to it, it just waits on
ServerSocket.accept().

I'm using jre1.4.2_04 on Linux - Red Hat 9

Is there some bug in java-Linux-socket implementation or in my code ?
Thanks in advance.

This is the result of system netstat (after a few clients failed to connect
to the server):

tcp 78 0 localhost:32323 localhost:2560 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2568 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2576 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2584 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2340 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2592 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2348 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2344 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2356 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2352 CLOSE_WAIT
tcp 78 0 localhost:32323 localhost:2608 CLOSE_WAIT

A snippet of the server source:

private class Server
{
        private ServerSocket _serverSckt = null;
        private boolean _break = false;

        ServerRunnable()
        {
            _serverSckt= new ServerSocket(32323);
            _serverSckt.setSoTimeout(2000);
        }

        public void exeServer()
        {
            try {
                Socket clientSckt = null;
                while (!_break)
                {
                    try {
                        clientSckt = _serverSckt.accept();

                    } catch (SocketTimeoutException ex) {
                        // ok, timeout occured, while loops again
                    } catch (InterruptedIOException ex) {
                        final String sMsg = "_serverSckt Interrupred!!!
managed to transfer " + ex.bytesTransferred + " [bytes]";
                        _LOGGER.error(sMsg, ex);
                    }

                    if (clientSckt != null) {

                        getClientHandler().handleClient(clientSckt); //
handles client in separate thread
                        // note: clientSckt is closed by client handler

                        clientSckt = null;
                    }
                }
            } catch (IOException e) {
                 _LOGGER.error(e);
            } catch (Throwable thr) {
                _LOGGER.fatal(thr);
            } finally {
                _serverRunning = false;
                try {
                    _serverSckt.close();
                } catch (IOException e) {
                    Assert.catchReport(e);
                }
            }
        }
}



Relevant Pages

  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • This is going straight to the pool room
    ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
    (comp.os.vms)
  • [Full-Disclosure] R: Full-Disclosure Digest, Vol 3, Issue 42
    ... Full-Disclosure Digest, Vol 3, Issue 42 ... SD Server 4.0.70 Directory Traversal Bug ... Arkeia Network Backup Client Remote Access ...
    (Full-Disclosure)
  • Re: What doesnt lend itself to OO?
    ... > rather than client code. ... no way to do that without also touching the object with clock semantics ... will not encapsulate both clock semantics and network semantics. ... The server can do whatever it wants ...
    (comp.object)
  • RE: Fax monitor incoming + outgoing calls?
    ... problem between the client computer and the SBS server. ... Client is using the internal IP address of the SBS server as the ... To the folder redirection GPO issue: ...
    (microsoft.public.windows.server.sbs)