Skip to content

Commit c33d16a

Browse files
authored
Update Watchdog.md
1 parent e0d188e commit c33d16a

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

docs/MinecraftApi/Watchdog.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Watchdog
22

3-
Watchdog is a performance watchdog system that is enabled in Minecraft script plugins by default.
3+
Watchdog is a performance system for script engine that is enabled in Minecraft script plugins by default.
44

55
## Server properties
66

7-
Watchdog configuration can be modified via `server.properties` in Dedicated Server. This features are added since 1.19.20.
7+
Watchdog configuration can be modified via `server.properties` in [Dedicated Server](https://www.minecraft.net/en-us/download/server/bedrock). This features are added since 1.19.20.
88

99
```properties
1010
# Enables the watchdog (default = true)
@@ -19,10 +19,12 @@ script-watchdog-spike-threshold=100
1919
# Sets the watchdog threshold for slow scripts over multiple ticks (default = 2ms)
2020
script-watchdog-slow-threshold=2
2121

22-
# Saves and shuts down the world when the combined memory usage exceeds the given threshold (in megabytes). Setting this value to 0 disables the limit. (default = 250)
22+
# Saves and shuts down the world when the combined memory usage exceeds the given threshold (in megabytes).
23+
# Setting this value to 0 disables the limit. (default = 250)
2324
script-watchdog-memory-limit=250
2425

25-
# Produces a content log warning when the combined memory usage exceeds the given threshold (in megabytes). Setting this value to 0 disables the warning. (default = 100)
26+
# Produces a content log warning when the combined memory usage exceeds the given threshold (in megabytes).
27+
# Setting this value to 0 disables the warning. (default = 100)
2628
script-watchdog-memory-warning=100
2729

2830
# Enables watchdog exception handling via the events.beforeWatchdogTerminate event (default = true)
@@ -39,34 +41,67 @@ script-watchdog-hang-exception=true
3941

4042
These watchdog errors are thrown with `[Watchdog]` label in error.
4143

42-
- Slow-running script detected in behavior pack '%s' (x ms average)
44+
---
4345

44-
Script runtime is delayed by over a certain timeframe. This
46+
### Slow-running script detected in behavior pack '%s' (x ms average)
4547

46-
- x ms script spike detected in behavior pack '%s'
48+
Script runtime is delayed by over a certain timeframe.
49+
50+
---
51+
52+
### x ms script spike detected in behavior pack '%s'
4753

4854
There is a spike in script runtime.
4955

50-
- Out of memory exception detected in behavior pack '%s'
56+
---
57+
58+
### Out of memory exception detected in behavior pack '%s'
5159

5260
This error occurs when the combined memory usage exceeds.
5361

5462
This saves and shuts down the world by Watchdog termination and cannot be canceled using `BeforeWatchdogTerminateEvent`.
5563

56-
- x ms script hang detected in behavior pack '%s'
64+
---
65+
66+
### x ms script hang detected in behavior pack '%s'
5767

5868
The scripts freezes at a certain location of your script for more than the watchdog threshold for single tick.
5969

6070
This is usually caused by iteration, such as `while` loop and `for` loop.
6171

62-
- Stack overflow detected in behavior pack '%s'
72+
---
73+
74+
### Stack overflow detected in behavior pack '%s'
6375

6476
Occurs when there is a recursive function (a function that calls itself) without an exit point.
6577

66-
- High memory usage detected
78+
---
79+
80+
### High memory usage detected
6781

6882
Produces a content log warning when the combined memory usage exceeds the given threshold in megabytes.
6983

70-
- Unhandled critical exception of type '%s' in behavior pack '%s'
84+
---
7185

72-
Produces a content log error when an unhandled critical exception occurs.
86+
### Unhandled critical exception of type '%s' in behavior pack '%s'
87+
88+
Produces a content log error when an unhandled critical exception occurs.
89+
90+
There are multiple reason that a watchdog is deciding to terminate execution of a behavior pack's script.
91+
- `hang`: script is not responsive due to a hang or infinite loop.
92+
- `stackOverflow`: a long, and potentially infinite chain of function calls.
93+
94+
## Script API
95+
96+
Using Minecraft's scripting API, you are able to connect to a callback that will be called when a script runtime is being terminated due to a violation of the performance watchdog system.
97+
98+
This event allows you to cancel the termination of the script runtime to prevent from the watchdog from stopping the server from running. Note that depending on server configuration settings, cancellation of the termination may not be allowed.
99+
100+
```js
101+
import { system } from '@minecraft/server';
102+
103+
system.events.beforeWatchdogTerminate.subscribe((event) => {
104+
event.cancel = true;
105+
});
106+
```
107+

0 commit comments

Comments
 (0)