BindToClose API Improvements

Hello Creators!

We are continuing to develop new ways to support our creators when it comes to GameServer memory and status insights. As you might know we have recently started a Server Memory Experiments to dynamically increase game server memory as well as made changes to gracefully shutdown experiences that overrun their memory budget.

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!

Thank you.

240 Likes

This topic was automatically opened after 10 minutes.

Seems to be quite a useful addition, so thank you :grin:

Also, what’s the name of the new Enum? (Assuming it isn’t Enum.CloseReason)

17 Likes

What are the main advantages of doing this specifically; instead of just using your own?


Also, how do you provide either of these, to determine the shutdown type?

10 Likes

Better server shut down handling i assume, you’d be able to run different functions depending on the close reason

10 Likes

The DeveloperUpdate one can be quite useful as a signal to teleport players to a new server

25 Likes

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.

8 Likes

so unkown but absolute W update :sunglasses::sunglasses::sunglasses:

7 Likes

Will this become integrated as an analytics stat?

19 Likes

how would we know when the game is shutting down exactly? like after the task.wait in the function?

5 Likes

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.”

8 Likes

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.

15 Likes

currently looking for the “omg i’ve waited for soooo many years, finally my life is fulfilled!” ahh comment

8 Likes

It is, Someone posted this helpful image in another thread.

20 Likes

There’s a Memory Limit? What’s the Memory Limit even?

5 Likes

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.

17 Likes

Memory limit for most servers is 6.5GB, whilst for larger (600?+) servers it’s 12GB.

12 Likes

Thanks!

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.

10 Likes

It’s not part of this update but it is something we want to consider for the future!

8 Likes

W update. This will help track why my servers keep crashing

6 Likes