Skip to content

Commit 3feed08

Browse files
authored
Increase default incoming_queue_length limit, log warning when a client violates it (#3171)
# Description of Changes Closes #3170 . Commit messages: ### Increase the default incoming-queue-length limit 2048 turned out to be too low a value for BitCraft, as their world upload process requests on the order of 6000 reducers very rapidly. We still feel that having a limit is valuable to prevent malicious or misguided clients from taking an arbitrarily large amount of host memory, so we bump the value to give us a wide safety error for BitCraft's needs but don't remove the limit entirely. ### Add log at `warn` when the host disconnects a client due to too many requests # API and ABI breaking changes N/a # Expected complexity level and risk 1 # Testing - [x] @mamcx to run a BitCraft bot test.
1 parent 2539824 commit 3feed08

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crates/client-api/src/routes/subscribe.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub struct WebSocketOptions {
296296
///
297297
/// If this number is exceeded, the client is disconnected.
298298
///
299-
/// Default: 2048
299+
/// Default: 16384
300300
#[serde(default = "WebSocketOptions::default_incoming_queue_length")]
301301
pub incoming_queue_length: NonZeroUsize,
302302
}
@@ -311,7 +311,7 @@ impl WebSocketOptions {
311311
const DEFAULT_PING_INTERVAL: Duration = Duration::from_secs(15);
312312
const DEFAULT_IDLE_TIMEOUT: Duration = Duration::from_secs(30);
313313
const DEFAULT_CLOSE_HANDSHAKE_TIMEOUT: Duration = Duration::from_millis(250);
314-
const DEFAULT_INCOMING_QUEUE_LENGTH: NonZeroUsize = NonZeroUsize::new(2048).expect("2048 > 0, qed");
314+
const DEFAULT_INCOMING_QUEUE_LENGTH: NonZeroUsize = NonZeroUsize::new(16384).expect("16384 > 0, qed");
315315

316316
const DEFAULT: Self = Self {
317317
ping_interval: Self::DEFAULT_PING_INTERVAL,
@@ -826,7 +826,9 @@ fn ws_recv_queue(
826826
log::warn!("client {client_id} sent message after close or error");
827827
};
828828

829-
let (tx, rx) = mpsc::channel(state.config.incoming_queue_length.get());
829+
let max_incoming_queue_length = state.config.incoming_queue_length.get();
830+
831+
let (tx, rx) = mpsc::channel(max_incoming_queue_length);
830832
let rx = MeteredReceiverStream {
831833
inner: MeteredReceiver::with_gauge(
832834
rx,
@@ -842,6 +844,8 @@ fn ws_recv_queue(
842844
match e {
843845
// If the queue is full, disconnect the client.
844846
mpsc::error::TrySendError::Full(item) => {
847+
let client_id = state.client_id;
848+
log::warn!("Client {client_id} exceeded incoming_queue_length limit of {max_incoming_queue_length} requests");
845849
// If we can't send close (send task already terminated):
846850
//
847851
// - Let downstream handlers know that we're closing,

0 commit comments

Comments
 (0)