TUN-1559: fix nil dereference in TunnelConfig.CloseConnOnce

This commit is contained in:
Adam Chalmers 2019-02-28 16:56:01 -06:00
parent f22202b31b
commit abdbc76a46
2 changed files with 10 additions and 3 deletions

View File

@ -315,8 +315,7 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
c.Set("url", "http://"+listener.Addr().String())
}
tunnelConfig, err := prepareTunnelConfig(c, buildInfo, version, logger, transportLogger)
tunnelConfig.CloseConnOnce = &closeConnOnce
tunnelConfig, err := prepareTunnelConfig(c, buildInfo, version, logger, transportLogger, &closeConnOnce)
if err != nil {
return err
}

View File

@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"time"
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
@ -136,7 +137,13 @@ If you don't have a certificate signed by Cloudflare, run the command:
return originCert, nil
}
func prepareTunnelConfig(c *cli.Context, buildInfo *origin.BuildInfo, version string, logger, transportLogger *logrus.Logger) (*origin.TunnelConfig, error) {
func prepareTunnelConfig(
c *cli.Context,
buildInfo *origin.BuildInfo,
version string, logger,
transportLogger *logrus.Logger,
closeConnOnce *sync.Once,
) (*origin.TunnelConfig, error) {
hostname, err := validation.ValidateHostname(c.String("hostname"))
if err != nil {
logger.WithError(err).Error("Invalid hostname")
@ -231,6 +238,7 @@ func prepareTunnelConfig(c *cli.Context, buildInfo *origin.BuildInfo, version st
NoChunkedEncoding: c.Bool("no-chunked-encoding"),
CompressionQuality: c.Uint64("compression-quality"),
IncidentLookup: origin.NewIncidentLookup(),
CloseConnOnce: closeConnOnce,
}, nil
}