From b99c047a0c7786626a5c6e20f5521cf981f214f3 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky (@xetorthio)" Date: Tue, 17 Oct 2017 01:42:59 +0200 Subject: [PATCH] Revert "Add session keep alive. If client doesn't send a keep alive, after a" This reverts commit 1b0d363ffe2b7265524a8c241648aa3473e8a991. --- config/config.go | 10 ---------- event/event.go | 1 - handlers/ws.go | 5 ----- scheduler/scheduler.go | 23 ++--------------------- www/assets/app.js | 7 +------ 5 files changed, 3 insertions(+), 43 deletions(-) diff --git a/config/config.go b/config/config.go index 0c0d6c8..56bbb33 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "flag" "fmt" - "log" "os" "regexp" "time" @@ -40,8 +39,6 @@ var SecureCookie *securecookie.SecureCookie var GithubClientID, GithubClientSecret string var FacebookClientID, FacebookClientSecret string var DockerClientID, DockerClientSecret string -var SessionKeepAlive time.Duration -var sessionKeepAlive string type stringslice []string @@ -75,7 +72,6 @@ func ParseFlags() { flag.StringVar(&SSHKeyPath, "ssh_key_path", "", "SSH Private Key to use") flag.StringVar(&CookieHashKey, "cookie-hash-key", "", "Hash key to use to validate cookies") flag.StringVar(&CookieBlockKey, "cookie-block-key", "", "Block key to use to encrypt cookies") - flag.StringVar(&sessionKeepAlive, "session-keep-alive", "5m", "Duration for which a session will be kept alive when no more heartbeats arrive") flag.StringVar(&GithubClientID, "oauth-github-client-id", "", "Github OAuth Client ID") flag.StringVar(&GithubClientSecret, "oauth-github-client-secret", "", "Github OAuth Client Secret") @@ -90,12 +86,6 @@ func ParseFlags() { SecureCookie = securecookie.New([]byte(CookieHashKey), []byte(CookieBlockKey)) - dur, err := time.ParseDuration(sessionKeepAlive) - if err != nil { - log.Fatalf("Cannot parse duration of flag [-session-keep-alive]. Got: %v\n", err) - } - SessionKeepAlive = dur - registerOAuthProviders() } diff --git a/event/event.go b/event/event.go index 190237c..225fe43 100644 --- a/event/event.go +++ b/event/event.go @@ -15,7 +15,6 @@ var ( SESSION_END = EventType("session end") SESSION_READY = EventType("session ready") SESSION_BUILDER_OUT = EventType("session builder out") - SESSION_KEEP_ALIVE = EventType("session keep alive") ) type Handler func(sessionId string, args ...interface{}) diff --git a/handlers/ws.go b/handlers/ws.go index b8f6cc5..b41b490 100644 --- a/handlers/ws.go +++ b/handlers/ws.go @@ -6,7 +6,6 @@ import ( "github.com/googollee/go-socket.io" "github.com/gorilla/mux" - "github.com/play-with-docker/play-with-docker/event" ) func WS(so socketio.Socket) { @@ -66,10 +65,6 @@ func WS(so socketio.Socket) { m.Close() core.ClientClose(client) }) - - so.On("session keep alive", func() { - e.Emit(event.SESSION_KEEP_ALIVE, sessionId) - }) } func WSError(so socketio.Socket) { diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 480dd06..3eb3b88 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -6,7 +6,6 @@ import ( "log" "time" - "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/pwd" "github.com/play-with-docker/play-with-docker/pwd/types" @@ -24,9 +23,8 @@ type SchedulerApi interface { } type scheduledSession struct { - session *types.Session - keepAlive *time.Timer - cancel context.CancelFunc + session *types.Session + cancel context.CancelFunc } type scheduledInstance struct { @@ -70,10 +68,6 @@ func (s *scheduler) processSession(ctx context.Context, ss *scheduledSession) { // Session has expired. Need to close the session. s.pwd.SessionClose(ss.session) return - case <-ss.keepAlive.C: - // No keep alive has been received after the defined interval - log.Printf("No keep alive has been received for session %s after %s. Closing.\n", ss.session.Id, config.SessionKeepAlive) - s.pwd.SessionClose(ss.session) case <-ctx.Done(): return } @@ -147,7 +141,6 @@ func (s *scheduler) scheduleSession(session *types.Session) { s.scheduledSessions[session.Id] = ss ctx, cancel := context.WithCancel(context.Background()) ss.cancel = cancel - ss.keepAlive = time.NewTimer(config.SessionKeepAlive) go s.processSession(ctx, ss) log.Printf("Scheduled session %s\n", session.Id) } @@ -232,18 +225,6 @@ func (s *scheduler) Start() error { instance := &types.Instance{Name: instanceName} s.unscheduleInstance(instance) }) - s.event.On(event.SESSION_KEEP_ALIVE, func(sessionId string, args ...interface{}) { - log.Printf("Keep alive recevied for session %s\n", sessionId) - if _, found := s.scheduledSessions[sessionId]; !found { - log.Printf("Session %s was not found. Ignoring.\n", sessionId) - return - } - ss := s.scheduledSessions[sessionId] - if ss.keepAlive.Stop() { - log.Printf("Keep alive reset for session %s\n", sessionId) - ss.keepAlive.Reset(config.SessionKeepAlive) - } - }) s.started = true return nil diff --git a/www/assets/app.js b/www/assets/app.js index 0337b80..ad1f584 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -181,8 +181,6 @@ var socket = io({ path: '/sessions/' + sessionId + '/ws' }); - - socket.on('instance terminal status', function(name, status) { var instance = $scope.idx[name]; instance.status = status; @@ -249,11 +247,8 @@ socket.on('connect_error', function() { $scope.connected = false; }); - socket.on('connect', function(s) { + socket.on('connect', function() { $scope.connected = true; - setInterval(function() { - socket.emit('session keep alive', 'keep me alive please! ' + new Date()); - }, 30*1000); }); socket.on('instance stats', function(stats) {