forked from TrueCloudLab/neoneo-go
rpc/server: make double-start a no-op
This commit is contained in:
parent
2c5fbd57fb
commit
4eee2f930e
1 changed files with 7 additions and 0 deletions
|
@ -50,6 +50,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"go.uber.org/atomic"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ type (
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
https *http.Server
|
https *http.Server
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
|
started *atomic.Bool
|
||||||
|
|
||||||
subsLock sync.RWMutex
|
subsLock sync.RWMutex
|
||||||
subscribers map[*subscriber]bool
|
subscribers map[*subscriber]bool
|
||||||
|
@ -188,6 +190,7 @@ func New(chain blockchainer.Blockchainer, conf rpc.Config, coreServer *network.S
|
||||||
oracle: orc,
|
oracle: orc,
|
||||||
https: tlsServer,
|
https: tlsServer,
|
||||||
shutdown: make(chan struct{}),
|
shutdown: make(chan struct{}),
|
||||||
|
started: atomic.NewBool(false),
|
||||||
|
|
||||||
subscribers: make(map[*subscriber]bool),
|
subscribers: make(map[*subscriber]bool),
|
||||||
// These are NOT buffered to preserve original order of events.
|
// These are NOT buffered to preserve original order of events.
|
||||||
|
@ -207,6 +210,10 @@ func (s *Server) Start(errChan chan error) {
|
||||||
s.log.Info("RPC server is not enabled")
|
s.log.Info("RPC server is not enabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !s.started.CAS(false, true) {
|
||||||
|
s.log.Info("RPC server already started")
|
||||||
|
return
|
||||||
|
}
|
||||||
s.Handler = http.HandlerFunc(s.handleHTTPRequest)
|
s.Handler = http.HandlerFunc(s.handleHTTPRequest)
|
||||||
s.log.Info("starting rpc-server", zap.String("endpoint", s.Addr))
|
s.log.Info("starting rpc-server", zap.String("endpoint", s.Addr))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue