Skip to content

Commit

Permalink
fix listen addr of tso service (#6110)
Browse files Browse the repository at this point in the history
ref #5836

Signed-off-by: Sen Han <00hnes@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
hnes and ti-chi-bot authored Mar 8, 2023
1 parent 9952911 commit 8cd4b16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/mcs/tso/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (

defaultName = "TSO"
defaultBackendEndpoints = "http://127.0.0.1:2379"
defaultListenAddr = "127.0.0.1:3379"
defaultListenAddr = "http://127.0.0.1:3379"

defaultTSOSaveInterval = time.Duration(utils.DefaultLeaderLease) * time.Second
defaultTSOUpdatePhysicalInterval = 50 * time.Millisecond
Expand Down
14 changes: 12 additions & 2 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Server struct {
clusterID uint64
rootPath string
storage endpoint.TSOStorage
listenURL *url.URL
backendUrls []url.URL

// for the primary election in the TSO cluster
Expand Down Expand Up @@ -438,6 +439,11 @@ func checkStream(streamCtx context.Context, cancel context.CancelFunc, done chan
<-done
}

// GetListenURL gets the listen URL.
func (s *Server) GetListenURL() *url.URL {
return s.listenURL
}

// GetConfig gets the config.
func (s *Server) GetConfig() *Config {
return s.cfg
Expand Down Expand Up @@ -579,10 +585,14 @@ func (s *Server) startServer() (err error) {
if err != nil {
return err
}
s.listenURL, err = url.Parse(s.cfg.ListenAddr)
if err != nil {
return err
}
if tlsConfig != nil {
s.muxListener, err = tls.Listen(utils.TCPNetworkStr, s.cfg.ListenAddr, tlsConfig)
s.muxListener, err = tls.Listen(utils.TCPNetworkStr, s.listenURL.Host, tlsConfig)
} else {
s.muxListener, err = net.Listen(utils.TCPNetworkStr, s.cfg.ListenAddr)
s.muxListener, err = net.Listen(utils.TCPNetworkStr, s.listenURL.Host)
}
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion tests/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (suite *tsoServerTestSuite) TestTSOServerStartAndStopNormally() {
}, testutil.WithWaitFor(5*time.Second), testutil.WithTickInterval(50*time.Millisecond))

// Test registered GRPC Service
cc, err := grpc.DialContext(suite.ctx, s.GetConfig().ListenAddr, grpc.WithInsecure())
cc, err := grpc.DialContext(suite.ctx, s.GetListenURL().Host, grpc.WithInsecure())
re.NoError(err)
cc.Close()
}
Expand Down
3 changes: 1 addition & 2 deletions tests/mcs/tso/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package tso
import (
"context"
"os"
"strings"
"time"

"github.com/pingcap/log"
Expand Down Expand Up @@ -70,7 +69,7 @@ func startSingleTSOTestServer(ctx context.Context, re *require.Assertions, backe
cfg, err := newTSOTestDefaultConfig()
re.NoError(err)
cfg.BackendEndpoints = backendEndpoints
cfg.ListenAddr = strings.TrimPrefix(tempurl.Alloc(), "http://")
cfg.ListenAddr = tempurl.Alloc()

s, cleanup, err := newTSOTestServer(ctx, re, cfg)
re.NoError(err)
Expand Down

0 comments on commit 8cd4b16

Please sign in to comment.