From 45137438db8217bbcb96203dd08bc91f88f6684c Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Fri, 8 Sep 2017 11:22:23 -0300 Subject: [PATCH] Make sure instance does not exist before reconnecting --- handlers/terms.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/handlers/terms.go b/handlers/terms.go index 0b4a1c6..734c78a 100644 --- a/handlers/terms.go +++ b/handlers/terms.go @@ -126,6 +126,12 @@ func (m *manager) process() { t := m.terminals[i.name] t.write <- i.data case instance := <-m.errorCh: + // check if it still exists before reconnecting + i := core.InstanceGet(&types.Session{Id: instance.SessionId}, instance.Name) + if i == nil { + log.Println("Instance doest not exist anymore. Won't reconnect") + continue + } log.Println("reconnecting") m.connect(instance) } @@ -177,11 +183,7 @@ func NewManager(s *types.Session) (*manager, error) { // There is a new instance in a session we are tracking. We should track it's terminal instanceName := args[0].(string) - instance := core.InstanceGet(s, instanceName) - if instance == nil { - log.Printf("Instance [%s] was not found in session [%s]\n", instanceName, sessionId) - return - } + instance := &types.Instance{Name: instanceName} m.disconnect(instance) })