diff --git a/environment/docker/container.go b/environment/docker/container.go index 6baf51d..c99694a 100644 --- a/environment/docker/container.go +++ b/environment/docker/container.go @@ -61,7 +61,11 @@ func (e *Environment) Attach() error { // from being reached until it is completed if not run in a seperate process. However, // we still want it to be stopped when the copy operation below is finished running which // indicates that the container is no longer running. - go e.pollResources(ctx) + go func(ctx context.Context) { + if err := e.pollResources(ctx); err != nil { + log.WithField("environment_id", e.Id).WithField("error", errors.WithStack(err)).Error("error during environment resource polling") + } + }(ctx) // Stream the reader output to the console which will then fire off events and handle console // throttling and sending the output to the user. diff --git a/environment/docker/stats.go b/environment/docker/stats.go index bd3f79b..94f57f7 100644 --- a/environment/docker/stats.go +++ b/environment/docker/stats.go @@ -38,11 +38,14 @@ func (e *Environment) pollResources(ctx context.Context) error { log.WithField("container_id", e.Id).Warn("encountered error processing docker stats output, stopping collection") } + log.WithField("container_id", e.Id).Debug("detected io.EOF, stopping resource polling") return nil } // Disable collection if the server is in an offline state and this process is still running. if e.State() == environment.ProcessOfflineState { + log.WithField("container_id", e.Id).Debug("process in offline state while resource polling is still active; stopping poll") + return nil } @@ -66,8 +69,11 @@ func (e *Environment) pollResources(ctx context.Context) error { }, } - b, _ := json.Marshal(st) - e.Events().Publish(environment.ResourceEvent, string(b)) + if b, err := json.Marshal(st); err != nil { + log.WithField("container_id", e.Id).WithField("error", errors.WithStack(err)).Warn("error while marshaling stats object for environment") + } else { + e.Events().Publish(environment.ResourceEvent, string(b)) + } } } } diff --git a/router/websocket/listeners.go b/router/websocket/listeners.go index 955236f..48b747e 100644 --- a/router/websocket/listeners.go +++ b/router/websocket/listeners.go @@ -28,7 +28,7 @@ func (h *Handler) ListenForExpiration(ctx context.Context) { if jwt != nil { if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 0 { _ = h.SendJson(&Message{Event: TokenExpiredEvent}) - } else if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 180 { + } else if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 60 { _ = h.SendJson(&Message{Event: TokenExpiringEvent}) } }