Skip to content
Closed
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
36 changes: 32 additions & 4 deletions engine/packages/guard-core/src/proxy_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2541,6 +2564,11 @@ fn to_hyper_close(frame: Option<CloseFrame>) -> 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(),
},
))
}
}
5 changes: 5 additions & 0 deletions scripts/run/engine-rocksdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading