From 4748d7cb294cba802894a27a8cc968fb061bc581 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 26 Sep 2020 17:35:11 -0700 Subject: [PATCH] Don't spam errors to the output if attempting to send a command to an unattached starting instance; closes pterodactyl/panel#2385 --- environment/docker/stream.go | 10 ++++++---- router/websocket/websocket.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/environment/docker/stream.go b/environment/docker/stream.go index 216018e..029fcce 100644 --- a/environment/docker/stream.go +++ b/environment/docker/stream.go @@ -15,6 +15,8 @@ type dockerLogLine struct { Log string `json:"log"` } +var ErrNotAttached = errors.New("not attached to instance") + func (e *Environment) setStream(s *types.HijackedResponse) { e.mu.Lock() e.stream = s @@ -24,13 +26,13 @@ func (e *Environment) setStream(s *types.HijackedResponse) { // Sends the specified command to the stdin of the running container instance. There is no // confirmation that this data is sent successfully, only that it gets pushed into the stdin. func (e *Environment) SendCommand(c string) error { + if !e.IsAttached() { + return ErrNotAttached + } + e.mu.RLock() defer e.mu.RUnlock() - if !e.IsAttached() { - return errors.New("attempting to send command to non-attached instance") - } - if e.meta.Stop != nil { // If the command being processed is the same as the process stop command then we want to mark // the server as entering the stopping state otherwise the process will stop and Wings will think diff --git a/router/websocket/websocket.go b/router/websocket/websocket.go index fad208b..8d947a3 100644 --- a/router/websocket/websocket.go +++ b/router/websocket/websocket.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/environment" + "github.com/pterodactyl/wings/environment/docker" "github.com/pterodactyl/wings/router/tokens" "github.com/pterodactyl/wings/server" "net/http" @@ -371,6 +372,18 @@ func (h *Handler) HandleInbound(m Message) error { return nil } + // TODO(dane): should probably add a new process state that is "booting environment" or something + // so that we can better handle this and only set the environment to booted once we're attached. + // + // Or maybe just an IsBooted function? + if h.server.GetState() == environment.ProcessStartingState { + if e, ok := h.server.Environment.(*docker.Environment); ok { + if !e.IsAttached() { + return nil + } + } + } + return h.server.Environment.SendCommand(strings.Join(m.Args, "")) } }