Skip to content

connection close on tunnel shutdown#18

Open
hvardhan-msft wants to merge 2 commits into
mainfrom
hvardhan/connection-close-on-tunnel-shutdown
Open

connection close on tunnel shutdown#18
hvardhan-msft wants to merge 2 commits into
mainfrom
hvardhan/connection-close-on-tunnel-shutdown

Conversation

@hvardhan-msft

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves QUIC tunnel shutdown behavior by explicitly closing connections on shutdown (so peers learn quickly), adds a constructor for wrapping an existing Quinn endpoint, and bumps the crate versions to the next alpha release.

Changes:

  • Add QuinnListenEndpoint::from_endpoint to wrap an already-created quinn::Endpoint.
  • On QuinnTunnel::close, emit a QUIC CONNECTION_CLOSE frame to notify the peer promptly.
  • Bump snocat / snocat-cli versions to 0.8.0-alpha.10 (and update lockfile).

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
snocat/src/common/tunnel_source/mod.rs Adds a new constructor for wrapping an existing Quinn endpoint.
snocat/src/common/protocol/tunnel/quinn_tunnel.rs Sends an explicit QUIC close frame when the tunnel is closed.
snocat/Cargo.toml Version bump to 0.8.0-alpha.10.
snocat-cli/Cargo.toml Updates snocat dependency version to match the new alpha.
Cargo.lock Lockfile update reflecting the version bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +65
/// Wrap an already-created quinn endpoint.
pub fn from_endpoint(bind_addr: SocketAddr, endpoint: quinn::Endpoint) -> Self {
Self {
bind_addr,
endpoint: Box::pin(endpoint),
accepting: None,
is_terminated: false,
}
}
Comment on lines +305 to +316
// Emit CONNECTION_CLOSE frame on the wire so the peer learns immediately
// rather than waiting for its own idle timeout to fire.
let error_code = match &reason {
TunnelCloseReason::Unspecified => quinn::VarInt::from_u32(0),
TunnelCloseReason::GracefulExit { .. } => quinn::VarInt::from_u32(0),
TunnelCloseReason::ApplicationErrorMessage(_) => quinn::VarInt::from_u32(1),
TunnelCloseReason::AuthenticationFailure { .. } => quinn::VarInt::from_u32(2),
_ => quinn::VarInt::from_u32(3),
};
let reason_str = format!("{}", reason);
let reason_bytes = &reason_str.as_bytes()[..reason_str.len().min(1024)];
self.connection.close(error_code, reason_bytes);
QuinnTunnel::close() now calls self.connection.close() to send a
CONNECTION_CLOSE frame on the wire before cancelling internal state.
Previously, the peer only learned about the closure via its own idle
timeout. With this change, the peer receives an immediate notification
and can reconnect to a different server within seconds.

Also adds QuinnListenEndpoint::from_endpoint() constructor so callers
can create the quinn::Endpoint externally, clone it for shutdown
coordination, and then wrap it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hvardhan-msft hvardhan-msft force-pushed the hvardhan/connection-close-on-tunnel-shutdown branch from 8290baf to c24b0ed Compare June 3, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants