diff options
-rw-r--r-- | rhimport/session.go | 2 | ||||
-rw-r--r-- | rhimport/session_store.go | 42 |
2 files changed, 24 insertions, 20 deletions
diff --git a/rhimport/session.go b/rhimport/session.go index b8b82ad..1c3439d 100644 --- a/rhimport/session.go +++ b/rhimport/session.go @@ -403,7 +403,7 @@ func newSession(ctx *Context, removeFunc func()) (session *Session) { session.state = SESSION_NEW session.removeFunc = removeFunc session.ctx = *ctx - session.quit = make(chan bool) + session.quit = make(chan bool, 1) session.done = make(chan bool) session.timer = time.NewTimer(10 * time.Second) session.cancelIntChan = make(chan bool, 1) diff --git a/rhimport/session_store.go b/rhimport/session_store.go index 4139f99..c26d943 100644 --- a/rhimport/session_store.go +++ b/rhimport/session_store.go @@ -162,24 +162,26 @@ func (store *SessionStore) new(ctx *Context, refId string) (resp newSessionRespo return } } - if id, err := generateSessionId(); err != nil { + id, err := generateSessionId() + if err != nil { resp.responsecode = http.StatusInternalServerError resp.errorstring = err.Error() - } else { - resp.id = id - if _, exists := store.store[ctx.UserName]; !exists { - newuser := &SessionStoreUserElement{} - newuser.sessions = make(map[string]*SessionStoreSessionElement) - store.store[ctx.UserName] = newuser - } - ctx.conf = store.conf - ctx.db = store.db - s := &SessionStoreSessionElement{newSession(ctx, func() { store.GetInterface().Remove(ctx.UserName, resp.id) }), refId} - store.store[ctx.UserName].sessions[resp.id] = s - resp.session = store.store[ctx.UserName].sessions[resp.id].s.getInterface() - rhdl.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id) - store.store[ctx.UserName].callUpdateHandlerAdd(resp.id, refId) + return } + + resp.id = id + if _, exists := store.store[ctx.UserName]; !exists { + newuser := &SessionStoreUserElement{} + newuser.sessions = make(map[string]*SessionStoreSessionElement) + store.store[ctx.UserName] = newuser + } + ctx.conf = store.conf + ctx.db = store.db + s := &SessionStoreSessionElement{newSession(ctx, func() { store.GetInterface().Remove(ctx.UserName, resp.id) }), refId} + store.store[ctx.UserName].sessions[resp.id] = s + resp.session = store.store[ctx.UserName].sessions[resp.id].s.getInterface() + rhdl.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id) + store.store[ctx.UserName].callUpdateHandlerAdd(resp.id, refId) return } @@ -191,15 +193,16 @@ func (store *SessionStore) get(username, id string) (resp getSessionResponse) { if !exists { resp.responsecode = http.StatusNotFound resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", username, id) + return } if session, exists := user.sessions[id]; exists { resp.session = session.s.getInterface() resp.refId = session.refId - } else { - resp.responsecode = http.StatusNotFound - resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", username, id) + return } + resp.responsecode = http.StatusNotFound + resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", username, id) return } @@ -242,6 +245,7 @@ func (store *SessionStore) remove(username, id string) (resp removeSessionRespon if !exists { resp.responsecode = http.StatusNotFound resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", username, id) + return } if session, exists := user.sessions[id]; exists { @@ -379,7 +383,7 @@ func NewSessionStore(conf *Config, db *rddb.DBChan) (store *SessionStore, err er store = new(SessionStore) store.conf = conf store.db = db - store.quit = make(chan bool) + store.quit = make(chan bool, 1) store.done = make(chan bool) store.store = make(map[string]*SessionStoreUserElement) store.newChan = make(chan newSessionRequest, 10) |