From dd83328c14c8fdd3ce533b409bc760166468ddea Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Thu, 17 Aug 2023 19:05:40 +0200 Subject: [PATCH] =?UTF-8?q?Don't=20propagate=20"not=20exist"=20error=20if?= =?UTF-8?q?=20trying=20to=20erase=20a=20session=20matchi=E2=80=A6=20(#252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary of Changes Don't consider "oserror.ErrNotExist" as a failure when trying to erase a session which corresponds to a missing file. Hello, in the current implementation, if a request contains a session token that has been stored in a file that has been deleted and we're trying to erase it using the Options.MaxAge = -1 workaround, the action still fails, because the missing file error gets propagated higher in the stack. This small fix prevents this, and ensures that the session is regenerated. ___ This is a reopen of #237 which was closed by the stale bot. Co-authored-by: Corey Daley --- store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store.go b/store.go index 7b6c5ec..aea37e4 100644 --- a/store.go +++ b/store.go @@ -211,7 +211,7 @@ func (s *FilesystemStore) Save(r *http.Request, w http.ResponseWriter, session *Session) error { // Delete if max-age is <= 0 if session.Options.MaxAge <= 0 { - if err := s.erase(session); err != nil { + if err := s.erase(session); err != nil && !os.IsNotExist(err) { return err } http.SetCookie(w, NewCookie(session.Name(), "", session.Options))