What would cause a duplicate session key? I occationally recieve the following error resulting in failure of several pieces of code later in the pipeline.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'QUyrgEInS_vO0GbrOhJffh6npb2ejlpllvS8Thn2pYY-Cu6Y9OkPd1qJuonzHQw2' for key 1: 
   UPDATE {sessions} 
   SET sid=:db_update_placeholder_0, ssid=:db_update_placeholder_1 
   WHERE (ssid = :db_condition_placeholder_0) ; 
Array ( 
   [:db_update_placeholder_0] =&gt; QUyrgEInS_vO0GbrOhJffh6npb2ejlpllvS8Thn2pYY 
   [:db_update_placeholder_1] =&gt; Cu6Y9OkPd1qJuonzHQw2JI67BDvO85pqp50SBsXE1ZU 
   [:db_condition_placeholder_0] =&gt; fMabX3y84Ngm-HcGF8MomLvLp1kmceLRIwniv_dSj_M ) 
in drupal_session_regenerate() (line 393 of /var/aegir/platforms/demandmetric/includes/session.inc).


I am using custom code that rougly looks like this:

drupal_session_start();
_$SESSION[''] = bunch of generated info.
Authorize linkedin
create user
$form_state['uid'] = $account-&gt;uid;
user_login_submit(array(), $form_state);
Update profile from linkedin info.


The error occurs on the user login submit part.

I suspect that drupal_session_start is causing the issue but I don't understand sessions well enough to debug this. The issue occurs 1 in about 30 users. I added the session start because the session info on line 2 doesn't get set without it.

Other suspects are memcache (very unlikely) and secure pages.

Anyone know about session that can enlighten me to how to track this issue down?
Check your sites/default/settings.php file, if you have $conf[https] = TRUE; then removing it will fix the error.

Removing it also won't affect any security issues as long as your server/domain is configured properly. You can also check the Enabling HTTP Secure page from Drupal.