Along those lines, we’re happy to announce some improvements to the BindToClose API
This new change to our BindToClose API will provide a “closeReason” argument to functions called after being bound using BindToClose(). We will pass one of the following enum’s as the closeReason to bound functions.
Close Reason
Description
Unknown
The server shut down for an unknown reason.
RobloxMaintenance
The server shut down for maintenance.
DeveloperShutdown
The experience developer has shut down the server, or functions bound by BindToClose() have been called inside Studio.
DeveloperUpdate
The experience developer has migrated the server to a new place version.
ServerEmpty
The last player has left and the experience is empty.
OutOfMemory
The experience has hit the memory limit for the game server.
Here is an example of how this new argument might be used:
game:BindToClose(function(closeReason)
print("Closing with reason", tostring(closeReason))
task.wait(3)
print("Done")
end)
Note: These changes are backwards compatible and current usages of BindToClose without the argument won’t be affected.
To take advantage of the new closeReason argument provided you will need to add the argument to your functions that you bind using BindToClose().
Please let us know if you have any questions or observe any issues!
This sounds like a great change! I can imagine devs could make use of this to track unexpected server shutdowns, which might be very useful for finding memory leaks.
The documentation of BindToClose states that “Multiple functions can be bound using BindToClose if it is called repeatedly. The game will wait a maximum of 30 seconds for all bound functions to complete running before shutting down. After 30 seconds, the game will shut down regardless if all bound functions have completed or not.”
It would be awesome if this could be added to our analytics as well. Would love to see a chart of average server lifetimes, as well as a display of which of these close reasons happens more often. It could be an actionable signal if we were to see high numbers of OutOfMemory, for example.
Just to clarify, When you now bind a function using BindToClose, The game server itself will pass the enum to your bound function as the first parameter. It’s not necessary for you to pass anything in your own code.
Previously creators didn’t have direct information as to why the server was closing.
We’re hoping creators find this useful for a variety of scenarios! Some experience developers who tested this feature have also found this helpful for tracking down memory leaks by collecting information for servers that shutdown due to the OutOfMemory reason.