Skip to content

Commit 6e96385

Browse files
docs: Add docs for the websocket ping interval configuration (#407)
1 parent 19c73ad commit 6e96385

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/06-concepts/07-configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ flowchart TB
1616
A --> B
1717
B --> C
1818
19-
%% Styles (optional tweak to your theme)
19+
%% Styles (optional - tweak to your theme)
2020
class A yaml
2121
class B env
2222
class C dart
@@ -69,6 +69,7 @@ These can be separately declared for each run mode in the corresponding yaml fil
6969
| SERVERPOD_FUTURE_CALL_EXECUTION_ENABLED | futureCallExecutionEnabled | true | Enables or disables the execution of future calls. |
7070
| SERVERPOD_FUTURE_CALL_CONCURRENCY_LIMIT | futureCall.concurrencyLimit | 1 | The maximum number of concurrent future calls allowed. If the value is negative or null, no limit is applied. |
7171
| SERVERPOD_FUTURE_CALL_SCAN_INTERVAL | futureCall.scanInterval | 5000 | The interval in milliseconds for scanning future calls |
72+
| SERVERPOD_WEBSOCKET_PING_INTERVAL | websocketPingInterval | 30 | The interval in seconds between WebSocket ping messages sent to keep streaming connections alive. Must be a positive integer. |
7273

7374
### Secrets
7475

@@ -165,6 +166,7 @@ apiServer:
165166
publicHost: localhost
166167
publicPort: 8080
167168
publicScheme: http
169+
websocketPingInterval: 30
168170
169171
insightsServer:
170172
port: 8081

docs/06-concepts/15-streams.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ Authentication is validated when the stream is first established, utilizing the
7979

8080
For more details on handling revoked authentication, refer to the section on [handling revoked authentication](authentication/custom-overrides#handling-revoked-authentication).
8181

82+
### WebSocket ping interval
83+
84+
The server sends periodic ping messages on open streaming connections to keep them alive. The interval between pings is configurable and defaults to 30 seconds.
85+
86+
If you deploy behind a load balancer or proxy with a shorter idle timeout (for example, 15-20 seconds), you may need to lower the ping interval so connections are not closed. Set the `SERVERPOD_WEBSOCKET_PING_INTERVAL` environment variable to the desired interval in seconds, or configure `websocketPingInterval` in your [configuration](./configuration) file.
87+
8288
### Error handling
8389

8490
Error handling works just like in regular endpoint methods in Serverpod. If an exception is thrown on a stream, the stream is closed with an exception. If the exception thrown is a serializable exception, the exception is first serialized and passed over the stream before it is closed.
@@ -110,8 +116,8 @@ outStream.listen((message) {
110116
inStream.addError(SerializableException('Error from client'));
111117
112118
// This will print
113-
// Server received error: Error from client
114-
// Client received error: Error from server
119+
// Server received error: Error from client
120+
// Client received error: Error from server
115121
```
116122

117123
In the example above, the client sends an error to the server, which then throws an exception back to the client. And since the exception is serializable, it is passed over the stream before the stream is closed.

0 commit comments

Comments
 (0)