Address race conditions when booting a server process

This commit is contained in:
Dane Everitt 2020-07-18 10:10:34 -07:00
parent daf682b991
commit 21303dc517
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 9 additions and 0 deletions

View File

@ -127,6 +127,9 @@ func (h *Handler) TokenValid() error {
return errors.New("jwt does not have connect permission") return errors.New("jwt does not have connect permission")
} }
h.server.RLock()
defer h.server.RUnlock()
if h.server.Uuid != j.ServerUUID { if h.server.Uuid != j.ServerUUID {
return errors.New("jwt server uuid mismatch") return errors.New("jwt server uuid mismatch")
} }
@ -247,6 +250,9 @@ func (h *Handler) HandleInbound(m Message) error {
if state == server.ProcessOfflineState { if state == server.ProcessOfflineState {
_ = h.server.Filesystem.HasSpaceAvailable() _ = h.server.Filesystem.HasSpaceAvailable()
h.server.Resources.RLock()
defer h.server.Resources.RUnlock()
resources := server.ResourceUsage{ resources := server.ResourceUsage{
Memory: 0, Memory: 0,
MemoryLimit: 0, MemoryLimit: 0,

View File

@ -33,6 +33,9 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
return errors.WithStack(err) return errors.WithStack(err)
} }
s.Lock()
defer s.Unlock()
// Don't explode if we're setting CPU limits to 0. Mergo sees that as an empty value // Don't explode if we're setting CPU limits to 0. Mergo sees that as an empty value
// so it won't override the value we've passed through in the API call. However, we can // so it won't override the value we've passed through in the API call. However, we can
// safely assume that we're passing through valid data structures here. I foresee this // safely assume that we're passing through valid data structures here. I foresee this