Help needed: Java Socket and close detection

Langer, Christoph christoph.langer at sap.com
Fri Jul 15 11:34:52 UTC 2016


Chris, David, Dmitry

thanks for your valuable input. This helps me a lot.

Best regards
Christoph

> -----Original Message-----
> From: Chris Hegarty [mailto:chris.hegarty at oracle.com]
> Sent: Donnerstag, 14. Juli 2016 12:31
> To: Langer, Christoph <christoph.langer at sap.com>
> Cc: net-dev at openjdk.java.net; nio-dev at openjdk.java.net
> Subject: Re: Help needed: Java Socket and close detection
> 
> Some further reading...
> 
> https://docs.oracle.com/javase/8/docs/technotes/guides/net/articles/connectio
> n_release.html
> 
> -Chris.
> 
> > On 13 Jul 2016, at 21:37, Dmitry Samersoff <dmitry.samersoff at oracle.com>
> wrote:
> >
> > Christoph,
> >
> > My $0.2
> >
> > Typically you see RST packet when the data come to a *closed* socket.
> > You shouldn't get RST if client/server communication shutdown properly.
> >
> > Also balancer may take a care about connection shutdown (it needs to
> > update internal tables) so it's possible that you never get RST after
> > balancer.
> >
> > Moreover, there are RST based attack and scanning methods so firewall
> > might be set to reject RST packets and doesn't pass it to inside network.
> >
> > I.e. IMHO, customer server should be updated to live without RST.
> >
> > -Dmitry
> >
> > On 2016-07-13 18:29, Langer, Christoph wrote:
> >> Hi folks,
> >>
> >>
> >>
> >> I have a question to the experts - regarding an issue that was reported
> >> to me by a customer.
> >>
> >>
> >>
> >> In the customer scenario they are running a Servlet engine and the
> >> Servlet is constantly sending data to a browser client. When the browser
> >> client is closed, the server does not get a notification of the other
> >> end having been terminated and is constantly sending out data and
> >> blocking an application thread. I'm under the assumption that the server
> >> should get an RST packet from the network upon writing/flushing data to
> >> the OutputStream as soon as the client is gone and hence an Exception
> >> should pop up but this isn't happening.
> >>
> >>
> >>
> >> There is a load balancer and maybe other network infrastructure involved
> >> in between the Servlet JVM and the browser client. We did some TCPDUMP
> >> tracing at the load balancer and we could not see an RST packet coming
> >> in from the client side. But when I'm running the scenario without all
> >> this network infrastructure involved, e.g. between servers and clients
> >> in the same network, I would always observe an RST packet once I close
> >> the browser. A FIN packet is received, too, but this does not lead to an
> >> Exception and to all my knowledge this can't be detected, not from the
> >> java Socket API and even less from the Servlet API which is just dealing
> >> with Streams.
> >>
> >>
> >>
> >> So my question to the experts is most of all: Would you agree that an
> >> RST packet should be generated in the network and received by the
> >> server? Or is it a normal behavior that servers must deal with not
> >> receiving RSTs and hence needing to wait for a timeout until e.g. the
> >> load balancer generates an RST? Also, is there any way to detect a FIN
> >> in the JVM and react on it?
> >>
> >>
> >>
> >> Thanks in advance and best regards
> >>
> >> Christoph
> >>
> >>
> >>
> >
> >
> > --
> > Dmitry Samersoff
> > Oracle Java development team, Saint Petersburg, Russia
> > * I would love to change the world, but they won't give me the sources.



More information about the nio-dev mailing list