Revert "Add session keep alive. If client doesn't send a keep alive, after a"

This reverts commit 1b0d363ffe.
This commit is contained in:
Jonathan Leibiusky (@xetorthio)
2017-10-17 01:42:59 +02:00
parent 94b59b7746
commit b99c047a0c
5 changed files with 3 additions and 43 deletions

View File

@@ -3,7 +3,6 @@ package config
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"regexp" "regexp"
"time" "time"
@@ -40,8 +39,6 @@ var SecureCookie *securecookie.SecureCookie
var GithubClientID, GithubClientSecret string var GithubClientID, GithubClientSecret string
var FacebookClientID, FacebookClientSecret string var FacebookClientID, FacebookClientSecret string
var DockerClientID, DockerClientSecret string var DockerClientID, DockerClientSecret string
var SessionKeepAlive time.Duration
var sessionKeepAlive string
type stringslice []string type stringslice []string
@@ -75,7 +72,6 @@ func ParseFlags() {
flag.StringVar(&SSHKeyPath, "ssh_key_path", "", "SSH Private Key to use") 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(&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(&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(&GithubClientID, "oauth-github-client-id", "", "Github OAuth Client ID")
flag.StringVar(&GithubClientSecret, "oauth-github-client-secret", "", "Github OAuth Client Secret") flag.StringVar(&GithubClientSecret, "oauth-github-client-secret", "", "Github OAuth Client Secret")
@@ -90,12 +86,6 @@ func ParseFlags() {
SecureCookie = securecookie.New([]byte(CookieHashKey), []byte(CookieBlockKey)) 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() registerOAuthProviders()
} }

View File

@@ -15,7 +15,6 @@ var (
SESSION_END = EventType("session end") SESSION_END = EventType("session end")
SESSION_READY = EventType("session ready") SESSION_READY = EventType("session ready")
SESSION_BUILDER_OUT = EventType("session builder out") SESSION_BUILDER_OUT = EventType("session builder out")
SESSION_KEEP_ALIVE = EventType("session keep alive")
) )
type Handler func(sessionId string, args ...interface{}) type Handler func(sessionId string, args ...interface{})

View File

@@ -6,7 +6,6 @@ import (
"github.com/googollee/go-socket.io" "github.com/googollee/go-socket.io"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/play-with-docker/play-with-docker/event"
) )
func WS(so socketio.Socket) { func WS(so socketio.Socket) {
@@ -66,10 +65,6 @@ func WS(so socketio.Socket) {
m.Close() m.Close()
core.ClientClose(client) core.ClientClose(client)
}) })
so.On("session keep alive", func() {
e.Emit(event.SESSION_KEEP_ALIVE, sessionId)
})
} }
func WSError(so socketio.Socket) { func WSError(so socketio.Socket) {

View File

@@ -6,7 +6,6 @@ import (
"log" "log"
"time" "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/event"
"github.com/play-with-docker/play-with-docker/pwd" "github.com/play-with-docker/play-with-docker/pwd"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"
@@ -24,9 +23,8 @@ type SchedulerApi interface {
} }
type scheduledSession struct { type scheduledSession struct {
session *types.Session session *types.Session
keepAlive *time.Timer cancel context.CancelFunc
cancel context.CancelFunc
} }
type scheduledInstance struct { type scheduledInstance struct {
@@ -70,10 +68,6 @@ func (s *scheduler) processSession(ctx context.Context, ss *scheduledSession) {
// Session has expired. Need to close the session. // Session has expired. Need to close the session.
s.pwd.SessionClose(ss.session) s.pwd.SessionClose(ss.session)
return 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(): case <-ctx.Done():
return return
} }
@@ -147,7 +141,6 @@ func (s *scheduler) scheduleSession(session *types.Session) {
s.scheduledSessions[session.Id] = ss s.scheduledSessions[session.Id] = ss
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
ss.cancel = cancel ss.cancel = cancel
ss.keepAlive = time.NewTimer(config.SessionKeepAlive)
go s.processSession(ctx, ss) go s.processSession(ctx, ss)
log.Printf("Scheduled session %s\n", session.Id) log.Printf("Scheduled session %s\n", session.Id)
} }
@@ -232,18 +225,6 @@ func (s *scheduler) Start() error {
instance := &types.Instance{Name: instanceName} instance := &types.Instance{Name: instanceName}
s.unscheduleInstance(instance) 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 s.started = true
return nil return nil

View File

@@ -181,8 +181,6 @@
var socket = io({ path: '/sessions/' + sessionId + '/ws' }); var socket = io({ path: '/sessions/' + sessionId + '/ws' });
socket.on('instance terminal status', function(name, status) { socket.on('instance terminal status', function(name, status) {
var instance = $scope.idx[name]; var instance = $scope.idx[name];
instance.status = status; instance.status = status;
@@ -249,11 +247,8 @@
socket.on('connect_error', function() { socket.on('connect_error', function() {
$scope.connected = false; $scope.connected = false;
}); });
socket.on('connect', function(s) { socket.on('connect', function() {
$scope.connected = true; $scope.connected = true;
setInterval(function() {
socket.emit('session keep alive', 'keep me alive please! ' + new Date());
}, 30*1000);
}); });
socket.on('instance stats', function(stats) { socket.on('instance stats', function(stats) {