From: Alexander Ebert Date: Sun, 8 Feb 2015 15:59:44 +0000 (+0100) Subject: Work-around for a race condition with parallel session initialization X-Git-Tag: 2.1.0_RC_1~53 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7ff7c082b86f44d2ce80cfe4606f6dcc22fa2de5;p=GitHub%2FWoltLab%2FWCF.git Work-around for a race condition with parallel session initialization --- diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 0337999cc1..b5e156d35c 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -514,7 +514,33 @@ class SessionHandler extends SingletonFactory { ); if ($spiderID !== null) $sessionData['spiderID'] = $spiderID; - $this->session = call_user_func(array($this->sessionEditorClassName, 'create'), $sessionData); + + try { + $this->session = call_user_func(array($this->sessionEditorClassName, 'create'), $sessionData); + } + catch (DatabaseException $e) { + // MySQL error 23000 = unique key + // do not check against the message itself, some weird systems localize them + if ($e->getCode() == 23000 && $this->supportsVirtualSessions) { + // find existing session + $session = call_user_func(array($this->sessionClassName, 'getSessionByUserID'), $this->user->userID); + + if ($session === null) { + // MySQL reported a unique key error, but no corresponding session exists, rethrow exception + throw $e; + } + else { + // inherit existing session + $this->session = $session; + $this->loadVirtualSession(true); + } + } + else { + // unrelated to user id + throw $e; + } + } + $this->firstVisit = true; $this->loadVirtualSession(true); }