Limits, failures and restarts
The limits the server puts on a script, and what happens when a script fails.
Memory
Each script has its own memory limit: 64 MB by default. An allocation beyond the limit fails; in Rust that usually ends the call with a fault, which counts as a failure (below).
- What your script keeps through handles (text components, command builders) counts against the limit. A call that would grow one past the limit is refused, and so is a JSON or legacy text that would expand past it.
- How many entities, items and displays your script holds at once is bounded by its memory limit, up to 131,072 handles. A call past that fails with a message that names the limit.
- Worlds and entities you create live in the server's memory, so keep their number bounded.
- The server holds your compiled code, which grows with the size of the script file, and the memory your script keeps while it runs. Keep your state small and load large data only when you need it.
The call deadline
When one call into your script runs your own code for longer than the deadline (5 seconds by default), the server stops that call. Time spent waiting for the server or for other scripts does not count, so a slow but working script is not stopped by it. A sleep inside your script does count.
A blocking handler that runs below the deadline is waited for: the player's action waits as long as your handler runs. Keep blocking handlers far below the deadline.
When your script fails
A failure is a fault in your code (a panic, a failed allocation), a call stopped at the deadline, or an event queue that reaches its limit (below). Then:
- The event a blocking handler was deciding gets that handler's failure verdict:
Denycancels it,Allowlets it go on (see Events and handler options). - The failed instance is discarded and your script is loaded again from the same file. Until the new instance has loaded, the old instance's blocking handlers keep answering with their failure verdicts, so there is no moment without protection.
- A script that fails three times within ten minutes is not restarted again. Its blocking handlers keep their failure verdicts until the owner reloads or removes it, and the console says so.
The answer a blocking handler returns for an event can never crash the server, whatever it holds.
Event queue
A non-blocking handler only observes. Its calls wait in your script's queue and every one is delivered, in order.
- Past 2,048 waiting calls, the console says
Plugin my-plugin is behind with events, at most once every 10 seconds. - At 65,536 waiting calls, the server stops the script as failed and restarts it, as above.
What one script can register
- Up to 1024 event handlers, events and extension events together.
- Up to 2048 command names at once, counting aliases and their
plugin:nameforms. - One command: up to 64 names with its aliases, up to 4096 nodes in its tree and up to 64 levels deep.
- A command name, alias, literal or extension event name is 1 to 128 bytes, with no space or control character.
- Up to 4096 permission nodes, about 4 MB in all.
- Up to 16,384 pending tasks at a time. A task ID belongs to the script that scheduled it and is not reused while the script is loaded.
Past a limit, the registration is refused. A refused permission returns an error; the others stop the call that asked, with an error in the console, so your script never runs half registered. Register what you need in on_load and look for the error in the console when you test.
Calls between scripts
Your script runs one call at a time. A server call you make can deliver an event back into your own script before it returns, so never hold a lock across a server call. When two scripts would wait for each other, the server refuses the call that would close the circle, and that call fails instead of hanging.
Find slow calls
The console command plugin time shows, for each script, how long the game waited for its blocking handlers and sync tasks: total time, number of calls, average and longest. Owners use these numbers to find slow scripts, so keep yours low.
A single wait of 100 ms or more prints a console line, at most once every 10 seconds per script. The line names the call (for example sync task #3, repeating, or the event of a handler) and says where the time went:
- in the script's own code (rounded to 25 ms steps);
- in its calls to the server;
- waiting for its turn, with the call of the same script that held the turn (
behind async task #7).
On a developer server, plugin profile <script> on also names the longest server calls of that call. plugin profile <script> off turns it off again (it is off by default).
Script names
- The names of Play Strawberry's own scripts (for example
user_interface,custom-models,miniscript,auth-liteand the-litescripts) are reserved. So are names that begin withstrawberryorplaystrawberry, andofficial,platform,staff,server,play,minecraftandmojang. Letter case, spaces,_,.and-do not make such a name different. - Two script names that differ only in letter case or by a space versus
_count as one name: the second script is refused at load with a message that names the first.
Items and titles
The server bounds what a script writes into an item or a title:
- At most 256 lore lines and 2 MiB of item data per item.
- A write that leaves a component the player's game cannot receive, such as custom data holding a text longer than 65,535 bytes, is refused.
- Boss bar and GUI titles hold at most 1 MiB of text.
A write past a bound is refused and the item stays as it was. try_set_component and the typed setters return the reason as their error; other writes stop the call with it.