diff --git a/engine/packages/guard-core/src/proxy_service.rs b/engine/packages/guard-core/src/proxy_service.rs index 0a47d055de..eac786680c 100644 --- a/engine/packages/guard-core/src/proxy_service.rs +++ b/engine/packages/guard-core/src/proxy_service.rs @@ -1858,11 +1858,34 @@ impl ProxyService { Ok(close_frame) => { tracing::debug!("websocket handler complete, closing"); - // Send graceful close - ws_handle.send(to_hyper_close(close_frame)).await?; + // Send graceful close. This may fail if client already sent + // close frame, which is normal. + tracing::debug!(?close_frame, "sending close frame to client"); + match ws_handle.send(to_hyper_close(close_frame)).await { + Ok(_) => { + tracing::debug!("close frame sent successfully"); + } + Err(err) => { + tracing::debug!( + ?err, + "failed to send close frame (websocket may be already closing)" + ); + } + } // Flush to ensure close frame is sent - ws_handle.flush().await?; + tracing::debug!("flushing websocket"); + match ws_handle.flush().await { + Ok(_) => { + tracing::debug!("websocket flushed successfully"); + } + Err(err) => { + tracing::debug!( + ?err, + "failed to flush websocket (websocket may be already closing)" + ); + } + } // Keep TCP connection open briefly to allow client to process close tokio::time::sleep(WEBSOCKET_CLOSE_LINGER).await; @@ -2541,6 +2564,11 @@ fn to_hyper_close(frame: Option) -> hyper_tungstenite::tungstenite:: }, )) } else { - tokio_tungstenite::tungstenite::Message::Close(None) + tokio_tungstenite::tungstenite::Message::Close(Some( + tokio_tungstenite::tungstenite::protocol::CloseFrame { + code: CloseCode::Normal, + reason: "ws.closed".into(), + }, + )) } } diff --git a/scripts/run/engine-rocksdb.sh b/scripts/run/engine-rocksdb.sh index ebe2725590..b3896cdb82 100755 --- a/scripts/run/engine-rocksdb.sh +++ b/scripts/run/engine-rocksdb.sh @@ -7,5 +7,10 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" cd "${REPO_ROOT}" RUST_LOG="${RUST_LOG:-debug}" \ +RIVET__PEGBOARD__RETRY_RESET_DURATION="100" \ +RIVET__PEGBOARD__BASE_RETRY_TIMEOUT="100" \ +RIVET__PEGBOARD__RESCHEDULE_BACKOFF_MAX_EXPONENT="1" \ +RIVET__PEGBOARD__RUNNER_ELIGIBLE_THRESHOLD="5000" \ +RIVET__PEGBOARD__RUNNER_LOST_THRESHOLD="7000" \ cargo run --bin rivet-engine -- start "$@" | tee /tmp/rivet-engine.log