3

I've written a multi-threaded UDP Proxy in Java using DatagramChannels.

It works fine until the following exception appears:

java.net.SocketException: Network dropped connection on reset: no further information 
at sun.nio.ch.DatagramChannelImpl.receive0(Native Method) 
at sun.nio.ch.DatagramChannelImpl.receiveIntoNativeBuffer(Unknown Source) 
at sun.nio.ch.DatagramChannelImpl.receive(Unknown Source) 
at sun.nio.ch.DatagramChannelImpl.receive(Unknown Source) 
at com.fabio.rotumaster.proxy.ProxyMain.handlePacket(ProxyMain.java:189) 
at com.fabio.rotumaster.proxy.ProxyMain.run(ProxyMain.java:169) 
at java.lang.Thread.run(Unknown Source) 

In ProxyMain.java on line 189 there is only the receive method being called:

SocketAddress sender = this.clientChannel.receive(buffer);

The error appears randomly from time to time. Sometimes only once and sometimes 5 of them in a row.

Does anyone have an idea?

modsfabio
  • 1,097
  • 1
  • 13
  • 29
  • Is there some timeout kicking in? – Fildor Mar 17 '17 at 08:43
  • The clientChannel is the main channel and when the exception occurs there were 10 other clients connected sending ~ 50 packets / second. This can't be a timeout of the DatagramChannel – modsfabio Mar 17 '17 at 08:45
  • Just came across the fact, that DatagramChannel does not support read timeout anyway, so this cannot be the reason. – Fildor Mar 17 '17 at 08:46
  • Other Qs and As on SO seem to indicate this might be a problem of the underlying OS (I guess Windows in your case). I'd just catch the exception and set up the channel again. Of course, this is only handling the strange behavior, not explaining the reason. And I am not sure if Messages can get lost that way. – Fildor Mar 17 '17 at 08:54
  • The OS is indeed Windows. I'm currently catching the exception immediately but there is no need to set up the channel again. The channel still says open and accepts connections. I was just wondering why this happens.. – modsfabio Mar 17 '17 at 08:57
  • So the channel is still "working" after the excpetion? That's odd. I hope @EJP sees this Q. He wrote some comments and answers to other similar questions. Maybe he has an idea. – Fildor Mar 17 '17 at 09:02
  • Exactly, the channel is still working normally. – modsfabio Mar 17 '17 at 09:05

1 Answers1

2

This is Winsock error 10052: WSAENETRESET:

Network dropped connection on reset.

The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. It can also be returned by setsockopt if an attempt is made to set SO_KEEPALIVE on a connection that has already failed.

How you can possibly get that on a UDP socket appears to be a mystery, but MSDN also says under recvfrom():

For a datagram socket, this error indicates that the time to live has expired.

And @David Schwartz says:

This is one of many errors that UDP implementations tend to uselessly report to applications. You pretty much have to ignore them all.

Community
  • 1
  • 1
user207421
  • 305,947
  • 44
  • 307
  • 483