Skip to content

Commit

Permalink
Fix a race condition on session creation.
Browse files Browse the repository at this point in the history
The SESSION object must be created while guarded by a lock, otherwise
NEXT-SESSION-ID may non-atomically increment a counter.
  • Loading branch information
stassats committed Nov 13, 2020
1 parent d684a90 commit fa36e20
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions session.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ case the function will also send a session cookie to the browser."
(let ((session (session *request*)))
(when session
(return-from start-session session))
(setf session (make-instance 'session)
(session *request*) session)
(with-session-lock-held ((session-db-lock *acceptor*))
(setf (session-db *acceptor*)
;; Must be under a lock because creating a new session increments a global counter
(setf session (make-instance 'session))
(setf (session *request*) session
(session-db *acceptor*)
(acons (session-id session) session (session-db *acceptor*))))
(set-cookie (session-cookie-name *acceptor*)
:value (session-cookie-value session)
Expand Down

0 comments on commit fa36e20

Please sign in to comment.