Sockets not cleaned up on Editor restart
I have an editor plugin which sets up a listener socket for third party clients to communicate with (on the same machine). The plugin fails to clean up the connection and the sockets on shutdown. The problem specifically arises when I do a restart of the Editor (with the same project or a new one which has the same plugin enabled). There is no problem when I quit UE4Editor altogether and then restart manually
I have the following code in my StartupModule function for UDP:
ShutdownModule function for UDP:
I've even tried putting this at the end:
The plugin does call my shutdown function when the editor restarts but when the new editor launches and tries to re-bind (in the startup module function) to the same address/port, it fails to create a socket through FUdpSocketBuilder, failing on Socket.Bind.
On further investigation using Microsoft's TCPView. I can see that the previous connection isn't terminated and the address/port is bound to the previous editor instance's connection.
(Note: I've also tried adding the AsReusable attribute to FUdpSocketBuilder).
I've seen similar behaviour in a TCP listener implementation. The code was as follows:
StartupModule for TCP
ShutdownModule for TCP
In TCP's case, the communication just fails silently (I assume the data is being sent to the previous editor process's port). Our new editor instance doesn't even receive the OnConnectionAccepted callback.
I checked in a fix for dangling socket handles on Windows (GitHub Commit). With that change I no longer see sockets not being closed. Can you try whether it fixes your problem as well? Thanks!
answered Nov 19 '14 at 12:12 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here