@@ -148,13 +148,6 @@ func (store *SessionStore) loadSessionFromString(value string) (*sessions.Sessio
148148// Clear clears any saved session information for a given ticket cookie
149149// from redis, and then clears the session
150150func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
151− requestCookie, _ := req.Cookie(store.CookieOptions.CookieName)
152−
153− val, _, ok := cookie.Validate(requestCookie, store.CookieOptions.CookieSecret, store.CookieOptions.CookieExpire)
154− if !ok {
155− return fmt.Errorf("Cookie Signature not valid")
156− }
157−
158151 // We go ahead and clear the cookie first, always.
159152 clearCookie := store.makeCookie(
160153 req,
@@ -164,6 +157,20 @@ func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) erro
164157 )
165158 http.SetCookie(rw, clearCookie)
166159
160+ // If there was an existing cookie we should clear the session in redis
161+ requestCookie, err := req.Cookie(store.CookieOptions.CookieName)
162+ if err != nil && err == http.ErrNoCookie {
163+ // No existing cookie so can't clear redis
164+ return nil
165+ } else if err != nil {
166+ return fmt.Errorf("error retrieving cookie: %v", err)
167+ }
168+
169+ val, _, ok := cookie.Validate(requestCookie, store.CookieOptions.CookieSecret, store.CookieOptions.CookieExpire)
170+ if !ok {
171+ return fmt.Errorf("Cookie Signature not valid")
172+ }
173+
167174 // We only return an error if we had an issue with redis
168175 // If there's an issue decoding the ticket, ignore it
169176 ticket, _ := decodeTicket(store.CookieOptions.CookieName, val)