I have a complex game based on timing. I depend on one server to do major backend things. In case of failure, I need to switch it with another server. To achieve this I used game:BindToClose() but I’ve learnt recently through some other devforum posts in the past that it’s not reliable and if it does fail, the entire game including every server would fail. MemoryService would be a good idea but it can’t work in this script at the moment. Anyone have any ideas or solutions to this problem?
Could you link that post, I have not heard of BindToClose being unreliable. The only thing I can think of is, if the server hard crashes, BindToClose wont work as the server went
How I’ve handled similar stuff is using MemoryStores, the server handling the backend stuff continuously updates the memory store so other servers reading it know that the server is still alive. When the server shuts down, it also clears the memory store, allowing another server to take server. If the server crashes or something happens, the memory store is no longer getting updated, and other servers reading it will notice it after a timeout period, and take over
The updating thing can be done by the server setting a “last update” time, and then servers checking the memory store would compare that last update time to the current time, and if the difference is higher than some timeout value, the other server will take over
Are you sure you’re waiting for all of work in :BindToClose to finish before it reaches the end of the function? If you have something like this:
game:BindToClose(function()
coroutine.wrap(function()
-- maybe calls to yielding functions like `:SetAsync`
end)()
end)
, then the coroutine will not be reliable because as soon as the engine reaches the end of :BindToClose, any further calls to yielding functions in the coroutine will end the script’s execution (so, for example, only the first call to :SetAsync will work).
Of these three snippets, only A and C work, and there’s the potential for more nuance with older functions like spawn.
A works because yielding calls like task.wait allow other yielded coroutines to resume. C works because the coroutine never gets into a “yielded” state.