Skip to content

Commit

Permalink
Rename startCloseMx to mtx
Browse files Browse the repository at this point in the history
  • Loading branch information
prettymuchbryce committed Apr 22, 2022
1 parent c3692c9 commit 15bac59
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type Server struct {
GRPCGatewayRouter *runtime.ServeMux
ClientCtx client.Context

logger log.Logger
metrics *telemetry.Metrics
logger log.Logger
metrics *telemetry.Metrics
// Start() is blocking and generally called from a separate goroutine.
// Close() can be called asynchronously and access shared memory
// via the listener. Therefore, we sync access to Start and Close with
// this mutex to avoid data races.
mtx sync.Mutex
mtx sync.Mutex
listener net.Listener
}

Expand Down Expand Up @@ -89,11 +89,11 @@ func New(clientCtx client.Context, logger log.Logger) *Server {
// and are delegated to the Tendermint JSON RPC server. The process is
// non-blocking, so an external signal handler must be used.
func (s *Server) Start(cfg config.Config) error {
s.startCloseMx.Lock()
s.mtx.Lock()
if cfg.Telemetry.Enabled {
m, err := telemetry.New(cfg.Telemetry)
if err != nil {
s.startCloseMx.Unlock()
s.mtx.Unlock()
return err
}

Expand All @@ -109,7 +109,7 @@ func (s *Server) Start(cfg config.Config) error {

listener, err := tmrpcserver.Listen(cfg.API.Address, tmCfg.MaxOpenConnections)
if err != nil {
s.startCloseMx.Unlock()
s.mtx.Unlock()
return err
}

Expand All @@ -120,19 +120,19 @@ func (s *Server) Start(cfg config.Config) error {

if cfg.API.EnableUnsafeCORS {
allowAllCORS := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))
s.startCloseMx.Unlock()
s.mtx.Unlock()
return tmrpcserver.Serve(s.listener, allowAllCORS(h), s.logger, tmCfg)
}

s.logger.Info("starting API server...")
s.startCloseMx.Unlock()
s.mtx.Unlock()
return tmrpcserver.Serve(s.listener, s.Router, s.logger, tmCfg)
}

// Close closes the API server.
func (s *Server) Close() error {
s.startCloseMx.Lock()
defer s.startCloseMx.Unlock()
s.mtx.Lock()
defer s.mtx.Unlock()
return s.listener.Close()
}

Expand Down

0 comments on commit 15bac59

Please sign in to comment.