Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38976

Re: server-side Socket does not recognize broken connection.

From Marcel Mueller <news.5.maazl@spamgourmet.org>
Newsgroups comp.lang.java.programmer
Subject Re: server-side Socket does not recognize broken connection.
Date 2019-06-01 16:08 +0200
Organization news.roellig-ltd.de for Open-News-Network e.V./news4
Message-ID <qcu0ti$ogl$1@news4.open-news-network.org> (permalink)
References <slrnqespnm.cfl.avl@logic.at>

Show all headers | View raw


Am 29.05.19 um 13:03 schrieb Andreas Leitgeb:
> A client (e.g. using plain old "telnet" on unix) connects, types a
> bit, then breaks the connection using Ctrl-] and "close", and is back
> on the shell. (closing the terminal window that's running telnet
> has same effect, ditto killing the telnet process - apparently
> whatever breaks, or even properly shuts down the connection from
> client side.)
> 
> The Socket on server side, however keeps reporting 0 on .available(),
> rather than throwing some exception for the broken socket.

Did you enable TCP keepalive? Without this option it may take an 
undefined time until a broken connection is recognized. Simply because 
it is not an error to send no data.

The situation only changes if /you/ send data over the socket. In this 
case the missing TCP ACK will be recognized after some retries.


> Single stepping the .available() method (class AbstractPlainSocketImpl)
> shows that it just never receives the ConnectionResetException, and thus
> won't ever get to throw new IOException("Stream closed.") itself.
> Field resetState never changes away from CONNECTION_NOT_RESET.

This could match with the above case.


> What am I doing wrong wrt. EOF-detection in ".available()" ?

There is no 'EOF condition' when the socket never receive a close from 
the client e.g. because the network connection is interrupted.

If only a process is canceled the operation system should clean up the 
remaining sockets. In this case there should not be a resource leak. (As 
long as the client sockets are not inherited by other still existing 
child processes.)
So you never can rely on that. TCP keepalive is AFAIK the only reliable 
way to identify unexpected client disconnects if you do not send data 
from time to time.


Marcel

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 11:03 +0000
  Re: server-side Socket does not recognize broken connection. Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-05-29 08:30 -0400
  Re: server-side Socket does not recognize broken connection. Joerg Meier <joergmmeier@arcor.de> - 2019-05-29 14:58 +0200
    Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 14:50 +0000
      Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 08:22 -0700
        Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2020-01-30 15:22 +0000
      Re: server-side Socket does not recognize broken connection. Martin Gregorie <martin@mydomain.invalid> - 2019-05-29 16:06 +0000
  Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 07:14 -0700
  Re: server-side Socket does not recognize broken connection. trisha guillot <guillottrisha347@gmail.com> - 2019-05-31 20:13 -0700
  Re: server-side Socket does not recognize broken connection. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-06-01 16:08 +0200

csiph-web