Work-around for concurrent attempts to create a virtual session
authorAlexander Ebert <ebert@woltlab.com>
Wed, 31 Dec 2014 12:47:46 +0000 (13:47 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 31 Dec 2014 12:47:46 +0000 (13:47 +0100)
wcfsetup/install/files/lib/system/session/SessionHandler.class.php

index c087d58bdd3178d982b7e3631b31113e84b30170..aa3a2929304318980030250e7399efd186738dba 100644 (file)
@@ -405,8 +405,18 @@ class SessionHandler extends SingletonFactory {
                        $this->virtualSession = null;
                        if ($this->user->userID && $this->supportsVirtualSessions) {
                                $virtualSessionAction = new SessionVirtualAction(array(), 'create', array('data' => array('sessionID' => $this->session->sessionID)));
-                               $returnValues = $virtualSessionAction->executeAction();
-                               $this->virtualSession = $returnValues['returnValues'];
+                               
+                               try {
+                                       $returnValues = $virtualSessionAction->executeAction();
+                                       $this->virtualSession = $returnValues['returnValues'];
+                               }
+                               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->virtualSession = SessionVirtual::getExistingSession($this->session->sessionID);
+                                       }
+                               }
                        }
                }
        }