Commit 1a28bc08 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Properly handle timeouts

parent 161d2d0a
......@@ -23,11 +23,13 @@ type SessionResult struct {
Err *irma.RemoteError
}
// Status is the status of an IRMA session.
type Status string
const (
StatusInitialized Status = "INITIALIZED"
StatusConnected Status = "CONNECTED"
StatusCancelled Status = "CANCELLED"
StatusDone Status = "DONE"
StatusInitialized Status = "INITIALIZED" // The session has been started and is waiting for the client
StatusConnected Status = "CONNECTED" // The client has retrieved the session request, we wait for its response
StatusCancelled Status = "CANCELLED" // The session is cancelled, possibly due to an error
StatusDone Status = "DONE" // The session has completed successfully
StatusTimeout Status = "TIMEOUT" // Session timed out
)
......@@ -18,7 +18,9 @@ import (
// Session helpers
func (session *session) finished() bool {
return session.status == irmaserver.StatusDone || session.status == irmaserver.StatusCancelled
return session.status == irmaserver.StatusDone ||
session.status == irmaserver.StatusCancelled ||
session.status == irmaserver.StatusTimeout
}
func (session *session) markAlive() {
......
......@@ -77,8 +77,14 @@ func (s memorySessionStore) deleteExpired() {
expired := make([]string, 0, len(s.m))
for token, session := range s.m {
if session.lastActive.Add(5 * time.Minute).Before(time.Now()) {
conf.Logger.Infof("Session %s expired, deleting", token)
expired = append(expired, token)
if !session.finished() {
conf.Logger.Infof("Session %s expired", token)
session.markAlive()
session.setStatus(irmaserver.StatusTimeout)
} else {
conf.Logger.Infof("Deleting %s", token)
expired = append(expired, token)
}
}
}
s.RUnlock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment