ServerSocket Misbehaving

I have a bug I’ve been chasing for months… It involves a ServerSocket that begins immediately closing connections after running some time within an OS X daemon.

Here’s what happens:
The service runs for days or weeks with no issues. Suddenly - usually after a weekend of the service running idle on a server - new clients connections are disconnected with a 102 error immediately upon connecting. Existing clients that remained connected still work. Disconnect a connected client and you cannot reconnect them either. Restarting the daemon immediately restores connectivity for all users.

The only time I’ve seen this behavior in the past is if the MaximumSocketsConnected is reached. So in debugging this I’ve monitored, ActiveConnections, MaximumSocketsConnected, IsListening property, app objectcount and app memory usage. Every logs perfectly normal before, during and after the ServerSocket starts closing connections.

Additional Data Points:
The issue appeared in a release when we changed two things:
(1) we updated our compiler from RealStudio 2011 to 2013 R3.3 and (2) we changed to using SSLSockets. This same app worked perfectly for years using the older compiler and standard TCPSockets.

(2) The same app compiled as a Windows service runs perfectly.

Does this issue sound familiar to anyone else? Any ideas on a fix or workaround?

Much appreciated,
Keith DeLong

Make sure the sslsockets are getting released. Put something in the destructor and log it.

Thanks Greg. I checked this early on but I’ll verify they are being released.

Any idea of this could this be related to the _AddPollableObject / _RemovePollableObject workaround (from Joe) that I’m using with 2013 R3.3? I’ve avoided later compilers as we have a number of customers still running OS X 10.6 Servers.

It could be. Are you calling _removepollableobject when an error occurs?

No, I added the following to my App class:

Sub _addpollableobject( item as _Pollable )
Super._AddPollableObject( item )
End Sub

Sub _removepollableobject( item as _Pollable )
Super._RemovePollableObject( item )
End Sub

I’ve seen something similar in a webserver I wrote for a product I used to sell. It was slightly different circumstances. SSL on a server socket. It typically only happened with Chrome, but I never was sure if it was strictly an SSL problem or a server socket problem. Chrome made more concurrent connections than the other browsers and I think that had something to do with.

Same results you see. It would get into a state where new connections would just immediately error with 102.

<https://xojo.com/issue/31800>

Kevin - Thank you. Interesting additional info in the Feedback case. There appears to be something internal to the ServerSocket that allows it to get into this state.

Greg - I did some testing and the sslsockets are getting released properly.