Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions libs/runtime/core/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,15 @@ impl Application {
) -> HashMap<String, Arc<dyn AuthGuardHandler + Send + Sync>> {
let mut guards = HashMap::new();
if let Some(names) = guard_names {
// This is only called in the setup phase, so using a thread-blocking lock is safe
// as the setup http server method will be the only caller accessing
// the custom auth guards map at this point.
let all_guards = self.custom_auth_guards.blocking_lock();
// Taken without blocking. Setup is the only thing touching this map
// at this point, so the lock is always free, and a blocking take
// panics outright when setup is called from inside a runtime, which
// is how an application with connection auth guards is started from
// an async context.
let Ok(all_guards) = self.custom_auth_guards.try_lock() else {
error!("custom auth guards were unavailable while setting up the server");
return guards;
};
for name in names {
if let Some(guard) = all_guards.get(name) {
guards.insert(name.clone(), guard.clone());
Expand Down
39 changes: 39 additions & 0 deletions libs/runtime/core/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,45 @@ pub const DEFAULT_DRAIN_TIMEOUT_SECS: u64 = 30;
// hints that arrive too late to be worth anything.
pub const CANCELLATION_BUFFER: usize = 256;

// How many messages may be waiting to be processed for one WebSocket connection
// before its read loop waits for room.
//
// Messages are handled off the read loop so that a slow handler cannot stop the
// connection answering heartbeats or noticing a close. This bounds how far a
// client can run ahead of its own handlers before it is pushed back on, which
// is a different situation from one handler being slow and deserves the
// backpressure.
pub const WS_CONNECTION_WORK_BUFFER: usize = 64;

// How long a connection's read loop waits for room in that buffer before it
// gives up on the client and closes the connection.
//
// The read loop answers heartbeats, so any time spent waiting here is time the
// connection appears dead to its client. The protocol's default heartbeat
// timeout is 5 seconds, so this stays well inside it: a burst gets a moment to
// drain, and a client that is genuinely outrunning its handlers is shed long
// before it would have concluded the connection was gone.
pub const WS_CONNECTION_WORK_SHED_GRACE_MS: u64 = 1_000;

// How long a closing connection waits for the messages it already accepted to
// finish before it abandons them and completes teardown.
//
// Until teardown completes the connection is still in the registry, still
// counted by the connection gauge, and its disconnect handler has not run, so
// this cannot wait on the queue draining at its own pace. Each queued message
// waits on its own handler timeout, and those add up, whereas a few seconds is
// enough for work that is nearly done to land.
pub const WS_CONNECTION_DRAIN_GRACE_MS: u64 = 5_000;

// The `retryAfter` hint sent in the close frame when a connection is shed for
// outrunning its handlers.
//
// The protocol has a server-initiated backoff, so the client waits at least this
// long before reconnecting rather than coming straight back into the same
// saturation. Clients take the greater of this and their own backoff and add
// their own jitter.
pub const WS_CONNECTION_SATURATED_RETRY_AFTER_MS: u64 = 5_000;

// How many dispatcher commands may be queued before a handler stream waits.
// Commands are small and are drained by a single task, so this only needs to
// absorb bursts of results arriving together.
Expand Down
Loading
Loading