mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 21:09:58 +00:00
TUN-8621: Prevent QUIC connection from closing before grace period after unregistering
Whenever cloudflared receives a SIGTERM or SIGINT it goes into graceful shutdown mode, which unregisters the connection and closes the control stream. Unregistering makes it so we no longer receive any new requests and makes the edge close the connection, allowing in-flight requests to finish (within a 3 minute period). This was working fine for http2 connections, but the quic proxy was cancelling the context as soon as the controls stream ended, forcing the process to stop immediately. This commit changes the behavior so that we wait the full grace period before cancelling the request
This commit is contained in:

committed by
Gonçalo Garcia

parent
ab0bce58f8
commit
e05939f1c9
@@ -23,7 +23,7 @@ type RegistrationClient interface {
|
||||
edgeAddress net.IP,
|
||||
) (*pogs.ConnectionDetails, error)
|
||||
SendLocalConfiguration(ctx context.Context, config []byte) error
|
||||
GracefulShutdown(ctx context.Context, gracePeriod time.Duration)
|
||||
GracefulShutdown(ctx context.Context, gracePeriod time.Duration) error
|
||||
Close()
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (r *registrationClient) SendLocalConfiguration(ctx context.Context, config
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *registrationClient) GracefulShutdown(ctx context.Context, gracePeriod time.Duration) {
|
||||
func (r *registrationClient) GracefulShutdown(ctx context.Context, gracePeriod time.Duration) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, gracePeriod)
|
||||
defer cancel()
|
||||
defer metrics.CapnpMetrics.ClientOperations.WithLabelValues(metrics.Registration, metrics.OperationUnregisterConnection).Inc()
|
||||
@@ -88,7 +88,9 @@ func (r *registrationClient) GracefulShutdown(ctx context.Context, gracePeriod t
|
||||
err := r.client.UnregisterConnection(ctx)
|
||||
if err != nil {
|
||||
metrics.CapnpMetrics.ClientFailures.WithLabelValues(metrics.Registration, metrics.OperationUnregisterConnection).Inc()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *registrationClient) Close() {
|
||||
|
Reference in New Issue
Block a user