From 249dcad1b398a10f349a907904cda988526eede3 Mon Sep 17 00:00:00 2001 From: Yuval Bar-On Date: Mon, 16 Feb 2026 16:02:33 +0100 Subject: [PATCH] fix: prevent deadlock in SessionData.Clear method (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move mutex unlock before calling Save() to prevent potential deadlock when Save() method needs to acquire the same mutex. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- session.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index 0985b90..d977ced 100644 --- a/session.go +++ b/session.go @@ -1548,9 +1548,10 @@ func (sd *SessionData) Clear(r *http.Request, w http.ResponseWriter) error { }() sd.sessionMutex.Lock() - defer sd.sessionMutex.Unlock() - sd.clearAllSessionData(r, true) + + // Release the lock before calling Save to prevent deadlock + sd.sessionMutex.Unlock() // This is primarily for testing - in production w will often be nil var err error