How do I prevent server 'hang forever' with RemoteFunctions

I was looking in the API about RemoteFunctions and noticed this text…
" If the client never returns a value, the server will hang forever."

This seems to be a fairly scary thing considering the unreliability of connections.
I don’t call functions server to client that often, but when I do, I don’t want to run the risk of having my server ‘hang forever’ on whatever thread the call is being made on.

So, what are some ways of either implementing a ‘timeout’ on the current thread if no response, or be able to ‘clean up’ when a player leaves. Also, how would I test any solution in studio?

I had the thought, if the RemoteFunction (which is part of my messaging system) were to be created and placed inside of the Player container, when a player connects, would this destroy any hanging threads if the player were to exit and the Player container destroyed? Or would the thread still be locked somewhere, taking up memory?

Don’t,

There should be a workaround using remote events to avoid this in the first place.

1 Like

Hah! I was just about to link this video as well LOL

But yeah, @dthecoolest brings up a very good video and it’s worth the watch. I don’t believe that there is a workaround for a “clean up” or a “timeout” on a thread if there is no response from the client, however, as you have stated, invoking the client is not a very good way to handle communication between server and client, for instance, the client can manipulate data that is handled on the server, or possibly yield a function forever.

The only workaround I could think of and have been using is just using a remote event. Having a remote called from the server to the client and the client back to the server is probably the safest, considering good sanity checks and no risk of forever-yielding.

2 Likes

XD Great video. I probably have only one instance of doing that, guess its time to change it up. :stuck_out_tongue: