Skip to content

Commit f2db255

Browse files
committed
chore(engine): tweak platform limits
1 parent 046e28c commit f2db255

File tree

24 files changed

+585
-85
lines changed

24 files changed

+585
-85
lines changed

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ Data structures often include:
189189

190190
- When talking about "Rivet Actors" make sure to capitalize "Rivet Actor" as a proper noun and lowercase "actor" as a generic noun
191191

192+
### Documentation Sync
193+
When making changes to the engine or RivetKit, ensure the corresponding documentation is updated:
194+
- **Limits changes** (e.g., max message sizes, timeouts): Update `website/src/content/docs/actors/limits.mdx`
195+
- **Config changes** (e.g., new config options in `engine/packages/config/`): Update `website/src/content/docs/self-hosting/configuration.mdx`
196+
- **RivetKit config changes** (e.g., `rivetkit-typescript/packages/rivetkit/src/registry/config/index.ts` or `rivetkit-typescript/packages/rivetkit/src/actor/config.ts`): Update `website/src/content/docs/actors/limits.mdx` if they affect limits/timeouts
197+
192198
### Comments
193199

194200
Documenting deltas is not important or useful. A developer who has never worked on the project will not gain extra information if you add a comment stating that something was removed or changed because they don't know what was there before. The only time you would be adding a comment for something NOT being there is if its unintuitive for why its not there in the first place.

engine/artifacts/errors/guard.request_body_too_large.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/artifacts/errors/guard.response_body_too_large.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/packages/config/src/config/guard.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ pub struct Guard {
1111
pub port: Option<u16>,
1212
/// Enable & configure HTTPS
1313
pub https: Option<Https>,
14+
/// Route cache TTL in milliseconds.
15+
pub route_cache_ttl_ms: Option<u64>,
16+
/// Proxy state cache TTL in milliseconds.
17+
pub proxy_state_cache_ttl_ms: Option<u64>,
18+
/// Time to keep TCP connection open after WebSocket close, in milliseconds.
19+
pub websocket_close_linger_ms: Option<u64>,
20+
/// Max incoming WebSocket message size in bytes.
21+
pub websocket_max_message_size: Option<usize>,
22+
/// Max outgoing WebSocket message size in bytes.
23+
pub websocket_max_outgoing_message_size: Option<usize>,
24+
/// Max HTTP request body size in bytes (first line of defense).
25+
pub http_max_request_body_size: Option<usize>,
26+
/// HTTP request timeout in seconds.
27+
pub http_request_timeout_secs: Option<u64>,
1428
}
1529

1630
impl Guard {
@@ -21,6 +35,35 @@ impl Guard {
2135
pub fn port(&self) -> u16 {
2236
self.port.unwrap_or(crate::defaults::ports::GUARD)
2337
}
38+
39+
pub fn route_cache_ttl_ms(&self) -> u64 {
40+
self.route_cache_ttl_ms.unwrap_or(10 * 60 * 1000) // 10 minutes
41+
}
42+
43+
pub fn proxy_state_cache_ttl_ms(&self) -> u64 {
44+
self.proxy_state_cache_ttl_ms.unwrap_or(60 * 60 * 1000) // 1 hour
45+
}
46+
47+
pub fn websocket_close_linger_ms(&self) -> u64 {
48+
self.websocket_close_linger_ms.unwrap_or(100)
49+
}
50+
51+
pub fn websocket_max_message_size(&self) -> usize {
52+
self.websocket_max_message_size.unwrap_or(32 * 1024 * 1024) // 32 MiB
53+
}
54+
55+
pub fn websocket_max_outgoing_message_size(&self) -> usize {
56+
self.websocket_max_outgoing_message_size
57+
.unwrap_or(32 * 1024 * 1024) // 32 MiB
58+
}
59+
60+
pub fn http_max_request_body_size(&self) -> usize {
61+
self.http_max_request_body_size.unwrap_or(256 * 1024 * 1024) // 256 MiB
62+
}
63+
64+
pub fn http_request_timeout_secs(&self) -> u64 {
65+
self.http_request_timeout_secs.unwrap_or(6 * 60) // 6 minutes
66+
}
2467
}
2568

2669
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]

engine/packages/config/src/config/pegboard.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,37 @@ pub struct Pegboard {
8686
///
8787
/// **Experimental**
8888
pub runner_pool_consecutive_successes_to_clear_error: Option<u32>,
89+
90+
// === Gateway Settings ===
91+
/// WebSocket open/handshake timeout in milliseconds.
92+
pub gateway_websocket_open_timeout_ms: Option<u64>,
93+
/// Timeout for response to start in milliseconds.
94+
pub gateway_response_start_timeout_ms: Option<u64>,
95+
/// Ping interval for gateway updates in milliseconds.
96+
pub gateway_update_ping_interval_ms: Option<u64>,
97+
/// GC interval for in-flight requests in milliseconds.
98+
pub gateway_gc_interval_ms: Option<u64>,
99+
/// Tunnel ping timeout in milliseconds.
100+
pub gateway_tunnel_ping_timeout_ms: Option<i64>,
101+
/// Hibernating WebSocket message ack timeout in milliseconds.
102+
pub gateway_hws_message_ack_timeout_ms: Option<u64>,
103+
/// Max pending message buffer size for hibernating WebSockets in bytes.
104+
pub gateway_hws_max_pending_size: Option<u64>,
105+
/// Max HTTP request body size in bytes for requests to actors.
106+
///
107+
/// Note: guard-core also enforces a larger limit (default 256 MiB) as a first line of defense.
108+
/// See `Guard::http_max_request_body_size`.
109+
pub gateway_http_max_request_body_size: Option<usize>,
110+
111+
// === Runner Settings ===
112+
/// Max HTTP response body size in bytes from actors.
113+
pub runner_http_max_response_body_size: Option<usize>,
114+
/// Ping interval for runner updates in milliseconds.
115+
pub runner_update_ping_interval_ms: Option<u64>,
116+
/// GC interval for actor event demuxer in milliseconds.
117+
pub runner_event_demuxer_gc_interval_ms: Option<u64>,
118+
/// Max time since last seen before actor is considered stale, in milliseconds.
119+
pub runner_event_demuxer_max_last_seen_ms: Option<u64>,
89120
}
90121

91122
impl Pegboard {
@@ -139,4 +170,60 @@ impl Pegboard {
139170
self.runner_pool_consecutive_successes_to_clear_error
140171
.unwrap_or(3)
141172
}
173+
174+
// === Gateway Settings ===
175+
176+
pub fn gateway_websocket_open_timeout_ms(&self) -> u64 {
177+
self.gateway_websocket_open_timeout_ms.unwrap_or(15_000)
178+
}
179+
180+
pub fn gateway_response_start_timeout_ms(&self) -> u64 {
181+
self.gateway_response_start_timeout_ms
182+
.unwrap_or(5 * 60 * 1000) // 5 minutes
183+
}
184+
185+
pub fn gateway_update_ping_interval_ms(&self) -> u64 {
186+
self.gateway_update_ping_interval_ms.unwrap_or(3_000)
187+
}
188+
189+
pub fn gateway_gc_interval_ms(&self) -> u64 {
190+
self.gateway_gc_interval_ms.unwrap_or(15_000)
191+
}
192+
193+
pub fn gateway_tunnel_ping_timeout_ms(&self) -> i64 {
194+
self.gateway_tunnel_ping_timeout_ms.unwrap_or(30_000)
195+
}
196+
197+
pub fn gateway_hws_message_ack_timeout_ms(&self) -> u64 {
198+
self.gateway_hws_message_ack_timeout_ms.unwrap_or(30_000)
199+
}
200+
201+
pub fn gateway_hws_max_pending_size(&self) -> u64 {
202+
self.gateway_hws_max_pending_size
203+
.unwrap_or(128 * 1024 * 1024) // 128 MiB
204+
}
205+
206+
pub fn gateway_http_max_request_body_size(&self) -> usize {
207+
self.gateway_http_max_request_body_size
208+
.unwrap_or(128 * 1024 * 1024) // 128 MiB
209+
}
210+
211+
// === Runner Settings ===
212+
213+
pub fn runner_http_max_response_body_size(&self) -> usize {
214+
self.runner_http_max_response_body_size
215+
.unwrap_or(128 * 1024 * 1024) // 128 MiB
216+
}
217+
218+
pub fn runner_update_ping_interval_ms(&self) -> u64 {
219+
self.runner_update_ping_interval_ms.unwrap_or(3_000)
220+
}
221+
222+
pub fn runner_event_demuxer_gc_interval_ms(&self) -> u64 {
223+
self.runner_event_demuxer_gc_interval_ms.unwrap_or(30_000)
224+
}
225+
226+
pub fn runner_event_demuxer_max_last_seen_ms(&self) -> u64 {
227+
self.runner_event_demuxer_max_last_seen_ms.unwrap_or(30_000)
228+
}
142229
}

engine/packages/guard-core/src/errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,15 @@ pub struct WebSocketServiceTimeout;
111111
"WebSocket target changed, retry not possible."
112112
)]
113113
pub struct WebSocketTargetChanged;
114+
115+
#[derive(RivetError, Serialize, Deserialize)]
116+
#[error(
117+
"guard",
118+
"request_body_too_large",
119+
"Request body too large.",
120+
"Request body size {size} bytes exceeds maximum allowed {max_size} bytes."
121+
)]
122+
pub struct RequestBodyTooLarge {
123+
pub size: usize,
124+
pub max_size: usize,
125+
}

0 commit comments

Comments
 (0)