mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 19:19:57 +00:00
TUN-1510: Wrap the close() in sync.Once.Do
This commit is contained in:
@@ -11,10 +11,9 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/cloudflare/cloudflared/h2mux"
|
||||
"github.com/cloudflare/cloudflared/tunnelrpc"
|
||||
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
|
||||
@@ -26,6 +25,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
_ "github.com/prometheus/client_golang/prometheus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
rpc "zombiezen.com/go/capnproto2/rpc"
|
||||
)
|
||||
|
||||
@@ -64,6 +64,7 @@ type TunnelConfig struct {
|
||||
WSGI bool
|
||||
CompressionQuality uint64
|
||||
IncidentLookup IncidentLookup
|
||||
CloseConnOnce *sync.Once // Used to close connectedSignal no more than once
|
||||
}
|
||||
|
||||
type dialError struct {
|
||||
@@ -161,11 +162,10 @@ func ServeTunnelLoop(ctx context.Context,
|
||||
config.Metrics.incrementHaConnections()
|
||||
defer config.Metrics.decrementHaConnections()
|
||||
backoff := BackoffHandler{MaxRetries: config.Retries}
|
||||
// Used to close connectedSignal no more than once
|
||||
connectedFuse := h2mux.NewBooleanFuse()
|
||||
go func() {
|
||||
if connectedFuse.Await() {
|
||||
close(connectedSignal)
|
||||
config.CloseConnOnce.Do(func() { close(connectedSignal) })
|
||||
}
|
||||
}()
|
||||
// Ensure the above goroutine will terminate if we return without connecting
|
||||
|
Reference in New Issue
Block a user