From 4ce9c83fad08ca0eef4a7c1734405c38389586e5 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 30 Nov 2019 15:46:28 -0800 Subject: [PATCH] [#3896cn] Fix nil pointer when passing data through patch --- server/update.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/update.go b/server/update.go index e7cf62e..91f4842 100644 --- a/server/update.go +++ b/server/update.go @@ -46,13 +46,22 @@ func (s *Server) UpdateDataStructure(data []byte) error { s.Container.OomDisabled = v } + // Mergo also cannot handle this boolean value. + if v, err := jsonparser.GetBoolean(data, "suspended"); err != nil { + if err != jsonparser.KeyPathNotFoundError { + return errors.WithStack(err) + } + } else { + s.Suspended = v + } + // Environment and Mappings should be treated as a full update at all times, never a // true patch, otherwise we can't know what we're passing along. - if len(src.EnvVars) > 0 { + if src.EnvVars != nil && len(src.EnvVars) > 0 { s.EnvVars = src.EnvVars } - if len(src.Allocations.Mappings) > 0 { + if src.Allocations != nil && src.Allocations.Mappings != nil && len(src.Allocations.Mappings) > 0 { s.Allocations.Mappings = src.Allocations.Mappings } @@ -89,6 +98,8 @@ func (s *Server) runBackgroundActions() { // yet, do it immediately. go func(server *Server) { if server.Suspended && server.State != ProcessOfflineState { + zap.S().Infow("server suspended with running process state, terminating now", zap.String("server", server.Uuid)) + if err := server.Environment.Terminate(os.Kill); err != nil { zap.S().Warnw( "failed to terminate server environment after seeing suspension",