Commits

Anonymous committed 4f70095

0.12.3dev: Catch concurrent creation of an authenticated session in `promote_session()`, and log a message instead of showing an error page.

Closes #7094.

Comments (0)

Files changed (1)

                         WHERE sid=%s
                         """, (self.req.authname, sid))
             else:
-                # we didn't have an anonymous session for this sid
-                cursor.execute("""
-                    INSERT INTO session (sid,last_visit,authenticated)
-                    VALUES (%s,%s,1)
-                    """, (self.req.authname, int(time.time())))
+                # We didn't have an anonymous session for this sid. The
+                # authenticated session might have been inserted between the
+                # SELECT above and here, so we catch the error.
+                try:
+                    cursor.execute("""
+                        INSERT INTO session (sid,last_visit,authenticated)
+                        VALUES (%s,%s,1)
+                        """, (self.req.authname, int(time.time())))
+                except Exception:
+                    self.env.log.warning('Authenticated session for %s '
+                                         'already exists', self.req.authname)
+                    db.rollback()
         self._new = False
 
         self.sid = sid