question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception: A socket operation was attempted to an unreachable host

See original GitHub issue

We have some systems that show the A socket operation was attempted to an unreachable host message and crash the application. It starts with the following exception:

System.Net.Sockets.SocketException (0x80004005): A socket operation was attempted to an unreachable host
   at System.Net.Sockets.Socket.SendTo(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
   at Rssdp.UdpSocket.SendTo(Byte[] messageData, UdpEndPoint endPoint)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.<>c__DisplayClass22_0.<SendMulticastMessage>b__0()
   at Rssdp.Infrastructure.SsdpCommunicationsServer.Repeat(Int32 repetitions, TimeSpan delay, Action work)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.SendMulticastMessage(Byte[] messageData)
   at Rssdp.Infrastructure.SsdpDevicePublisherBase.SendAliveNotification(SsdpDevice device, String notificationType, String uniqueServiceName)
   at Rssdp.Infrastructure.SsdpDevicePublisherBase.SendAliveNotifications(SsdpDevice device, Boolean isRoot)
   at Rssdp.Infrastructure.SsdpDevicePublisherBase.SendAllAliveNotifications(Object state)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()

This exception cannot be handled by user code, because it is running from a timer. Our application is running as a service that automatically restarts (after 90 seconds). When the service restarts, then the following exception occurs when the SsdpDevicePublisherBase constructor is invoked:

System.Net.Sockets.SocketException (0x80004005): A socket operation was attempted to an unreachable host
   at System.Net.Sockets.Socket.setMulticastOption(SocketOptionName optionName, MulticastOption MR)
   at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Object optionValue)
   at Rssdp.SocketFactory.CreateUdpMulticastSocket(String ipAddress, Int32 multicastTimeToLive, Int32 localPort)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.ListenForBroadcastsAsync()
   at Rssdp.Infrastructure.SsdpCommunicationsServer.BeginListeningForBroadcasts()
   at Rssdp.Infrastructure.SsdpDevicePublisherBase..ctor(ISsdpCommunicationsServer communicationsServer, String osName, String osVersion)
   at Rssdp.SsdpDevicePublisher..ctor()

We always invoke the SsdpDevicePublisherBase with a ISsdpCommunicationsServer that is initialized like this: new SsdpCommunicationsServer(new SocketFactory("0.0.0.0"), 2869); Our service keeps restarting, but after a while it starts working again and everything seems to be fine again.

There are some environmental issues that might have impact:

  • There are multiple systems in the network that advertise using RSSDP.
  • Our systems are equiped with two network adapters and a virtual TUN/TAP adapter that is bridged to one of the network adapters.

Unfortunately, I don’t have an exact reproduction scenario, but it happens on multiple systems (that are in different LANs).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Yortwcommented, May 12, 2019

Hi,

Thanks for following up on this and reporting back, that’s really great. I’ve been thinking about it, but I agree with you that this sort of problem seems best handled by the application code rather than the library. The application is in a better place to know how long it wants to wait/retry, what dependencies there might be, or if it even runs shortly after boot (not everything using RSSDP will). I’d like for the library to work as well as possible out of the box and ‘lead people into the pit of success’ , but I don’t think this particular case is something the library should handle itself.

Great to have the issue understood and documented though. Are you ok if we close this issue now?

Thanks again.

0reactions
ramondekleincommented, May 9, 2019

I have found that this issue only pops up directly after a reboot. Our service is registered to start during boot with start-type “automatic”. When I set the startup type of the service to “automatic (delayed)” then it works fine. This is the log that shows when the socket cannot be created:

2019-05-09 10:00:25,373 [  9] ERROR XXX.Common.Logging.Log4NetLogger: Unable to start SSDP advertisement.
2019-05-09 10:00:25,373 [  9] ERROR XXX.Common.Logging.Log4NetLogger: - Exception:
System.Net.Sockets.SocketException (0x80004005): Er is geprobeerd een socketbewerking uit te voeren op een onbereikbare host
   bij System.Net.Sockets.Socket.setMulticastOption(SocketOptionName optionName, MulticastOption MR)
   bij Rssdp.SocketFactory.CreateUdpMulticastSocket(Int32 multicastTimeToLive, Int32 localPort)
   bij Rssdp.Infrastructure.SsdpCommunicationsServer.BeginListeningForBroadcasts()
   bij Rssdp.Infrastructure.SsdpDevicePublisherBase..ctor(ISsdpCommunicationsServer communicationsServer, String osName, String osVersion, ISsdpLogger log)
   bij XXX.Client.DevicePublisher..ctor()
   bij XXX.Client.ClientDevice.<AdvertiseAsync>d__70.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij XXX.ClientService.SsdpService.<AdvertiseDeviceAsync>d__5.MoveNext()

My service currently depends on the Http service and LanmanServer service. I need the HTTP service, because I have an HttpListener in my application and I was hoping that the network layer would have been complete initialized afther the LanmanServer was ready. When I also add the Network Store Interface Service as a dependency, then this issue is gone.

I don’t think this is an actual bug in RSSDP, but the network is simply not available yet. I also notice some other network glitches directly after startup. My services runs on the 192.168.87.0/24 network and I have also seen messages that this network isn’t available yet. After 1-3 seconds, then this message disappears and the connection works fine.

PS: Error handling is fine, because I get an exception during the construction of the device publisher…

Read more comments on GitHub >

github_iconTop Results From Across the Web

A socket operation was attempted to an unreachable host
This error indicates that the network was not connected or not configured correctly. It is definitely an error on the client machine, ...
Read more >
Getting Error message" A socket operation was attempted ...
Original title: a socket operation was attemted to an unreachable network , this usually means the local software knows no route to reach...
Read more >
[FIX] A Socket Operation was Attempted to an Unreachable ...
A socket operation was attempted to an unreachable network error is network issues. Usually, the error appears in a client machine.
Read more >
Error: a socket operation was attempted to an unreachable ...
This error message indicates an issue with the network connectivity to the DynamoDB service. Specifically, it means that a socket operation was attempted...
Read more >
"A socket operation was attempted to an unreachable ...
Issue: When sending a network rendering job from Backburner, the following error message appears on the Backburner Server program:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found