Fixed Server Error XF\Db\Exception: MySQL query error - Duplicate entry for key "User Name"

Dnyan

Well-known member
Affected version
Beta 4
I got 2 such error for duplicate entry for key 'username'

Is it a bug or something which i need to look into to avoid duplicate user name

Please suggest, how can i avoid duplicate entry.

Thank You
 
i deleted that error, it happen twice for 2 different users.

when user registered with same username.

it had msg saying the key 'username' and the id of old member duplicate entry.

currently i changed the user name by adding some words to the new one.

I will provide you details if it happens again.
 
I haven't been able to reproduce this so far, either with public registration or adding a new user in the ACP.
 
I too not got same error again but it deleted 2 user from my total user number.

Earlier i got spam alert for some users so ideleted them (total 4 instance)

Now my total user number i.e. - id of last registered member goes +6 compare to total number of members.
 
The database system doesn't re-use IDs, so if you have six users in your database with sequential IDs, then delete users with ID 5 and 6, the next user to be created will be ID 7, not 5.
 
As there is no information on the error nor a current way to reproduce the issue, please just create a new report (with as much detail as possible) if this problem happens again.
 
XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry 'Name deleted as its of no use here' for key 'username'
src/XF/Db/AbstractStatement.php:212
Generated by: Unknown account Oct 31, 2017 at 5:10 PM

Today i got this error below is stack trace
Code:
Stack trace
INSERT  INTO xf_user (`visible`, `activity_visible`, `user_group_id`, `timezone`, `language_id`, `username`, `email`, `user_state`, `display_style_group_id`, `secondary_group_ids`, `secret_key`, `user_id`, `style_id`, `permission_combination_id`, `message_count`, `alerts_unread`, `conversations_unread`, `register_date`, `last_activity`, `trophy_points`, `avatar_date`, `avatar_width`, `avatar_height`, `avatar_highdpi`, `gravatar`, `is_moderator`, `is_admin`, `is_staff`, `is_banned`, `like_count`, `custom_title`, `warning_points`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
------------

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1062, '23000')
#1 src/XF/Db/Mysqli/Statement.php(69): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1062, '23000')
#2 src/XF/Db/AbstractAdapter.php(69): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(144): XF\Db\AbstractAdapter->query('INSERT  INTO xf...', Array)
#4 src/XF/Mvc/Entity/Entity.php(1343): XF\Db\AbstractAdapter->insert('xf_user', Array)
#5 src/XF/Mvc/Entity/Entity.php(1085): XF\Mvc\Entity\Entity->_saveToSource()
#6 src/XF/Service/User/Registration.php(254): XF\Mvc\Entity\Entity->save()
#7 src/XF/Service/ValidateAndSavableTrait.php(40): XF\Service\User\Registration->_save()
#8 src/XF/Pub/Controller/Register.php(367): XF\Service\User\Registration->save()
#9 src/XF/Mvc/Dispatcher.php(249): XF\Pub\Controller\Register->actionRegister(Object(XF\Mvc\ParameterBag))
#10 src/XF/Mvc/Dispatcher.php(87): XF\Mvc\Dispatcher->dispatchClass('XF:Register', 'Register', 'json', Object(XF\Mvc\ParameterBag), '', Object(XF\Pub\Controller\Register), NULL)
#11 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#12 src/XF/App.php(1844): XF\Mvc\Dispatcher->run()
#13 src/XF.php(328): XF\App->run()
#14 index.php(13): XF::runApp('XF\\Pub\\App')
#15 {main}

Is it a bug or something else which i need to look in.
 
Request state
Code:
array(4) {
  ["url"] => string(18) "/register/register"
  ["referrer"] => string(28) "https://civil4m.com/register"
  ["_GET"] => array(1) {
    ["/register/register"] => string(0) ""
  }
  ["_POST"] => array(15) {
    ["username"] => string(0) ""
    ["e6505adaf1709dd26386123419873a551492e4bd"] => string(13) "Pawan thakare"
    ["5e3e4c3bcd88d71cf4f7c2a35258484cea72d3a9"] => string(24) "pawanthakare55@gmail.com"
    ["email"] => string(0) ""
    ["6f97ecff461b60dcda3fbcd5c6398675d784ad69"] => string(8) "********"
    ["dob_month"] => string(1) "6"
    ["dob_day"] => string(2) "30"
    ["dob_year"] => string(4) "1996"
    ["location"] => string(10) "Chandrapur"
    ["reg_key"] => string(16) "9CnHK_7D17RaQNhh"
    ["11d28b8ae9470f972a8033947ba9e78db966f0eb"] => string(12) "Asia/Kolkata"
    ["_xfToken"] => string(8) "********"
    ["_xfRequestUri"] => string(9) "/register"
    ["_xfWithData"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
  }
}
 
Today Again 4 error of same type logged.

XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry '********' for key 'username'

src/XF/Db/AbstractStatement.php:212
Generated by: Unknown account
Nov 11, 2017 at 10:15 AM

Code:
Stack trace
INSERT  INTO xf_user (`visible`, `activity_visible`, `user_group_id`, `timezone`, `language_id`, `username`, `email`, `user_state`, `display_style_group_id`, `secondary_group_ids`, `secret_key`, `user_id`, `style_id`, `permission_combination_id`, `message_count`, `alerts_unread`, `conversations_unread`, `register_date`, `last_activity`, `trophy_points`, `avatar_date`, `avatar_width`, `avatar_height`, `avatar_highdpi`, `gravatar`, `is_moderator`, `is_admin`, `is_staff`, `is_banned`, `like_count`, `custom_title`, `warning_points`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
------------

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1062, '23000')
#1 src/XF/Db/Mysqli/Statement.php(70): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1062, '23000')
#2 src/XF/Db/AbstractAdapter.php(69): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(146): XF\Db\AbstractAdapter->query('INSERT  INTO xf...', Array)
#4 src/XF/Mvc/Entity/Entity.php(1343): XF\Db\AbstractAdapter->insert('xf_user', Array)
#5 src/XF/Mvc/Entity/Entity.php(1085): XF\Mvc\Entity\Entity->_saveToSource()
#6 src/XF/Service/User/Registration.php(254): XF\Mvc\Entity\Entity->save()
#7 src/XF/Service/ValidateAndSavableTrait.php(40): XF\Service\User\Registration->_save()
#8 src/XF/Pub/Controller/Register.php(369): XF\Service\User\Registration->save()
#9 src/XF/Mvc/Dispatcher.php(249): XF\Pub\Controller\Register->actionRegister(Object(XF\Mvc\ParameterBag))
#10 src/XF/Mvc/Dispatcher.php(89): XF\Mvc\Dispatcher->dispatchClass('XF:Register', 'register', 'json', Object(XF\Mvc\ParameterBag), '', Object(XF\Pub\Controller\Register), NULL)
#11 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#12 src/XF/App.php(1852): XF\Mvc\Dispatcher->run()
#13 src/XF.php(328): XF\App->run()
#14 index.php(13): XF::runApp('XF\\Pub\\App')
#15 {main}

array(4) { ["url"] => string(18) "/register/register" ["referrer"] => string(28) "https://civil4m.com/register" ["_GET"] => array(1) { ["/register/register"] => string(0) "" } ["_POST"] => array(15) { ["username"] => string(0) "" ["9c4eb2d7504af1d10060f366b44fea310a942d33"] => string(11) "Javed shaik" ["bb9b315c52a4920ee21562f500dd86d0cfd8129b"] => string(0) "" ["fa4a0a361a345cd7315fa33e365b0aa0d73a18a0"] => string(23) "javedshaik687@gmail.com" ["59eb9c2405d7c8f94f0cfdea131a6dd14e40fec4"] => string(8) "********" ["dob_month"] => string(1) "8" ["dob_day"] => string(2) "22" ["dob_year"] => string(4) "1994" ["location"] => string(7) "Sharjah" ["reg_key"] => string(16) "NDrpGzXlKzhop5ix" ["adf9c261aba97cd81239bceb9b88d8779e1d7cd3"] => string(13) "Europe/Moscow" ["_xfToken"] => string(8) "********" ["_xfRequestUri"] => string(9) "/register" ["_xfWithData"] => string(1) "1" ["_xfResponseType"] => string(4) "json" } }

Kindly look into it and please help me.
 
We will investigate it, though it's very likely a race condition and likely to be exacerbated by server issues (which you have posted about elsewhere). In terms of it being a race condition, it can be disregarded, but trying to identify the inconsistent server performance issues you're having would very likely help resolve the issue.
 
I believe the window for this became bigger due to anti-spam checks. I have made changes to reduce the window for this significantly, though it is still theoretically possible (as are similar race conditions elsewhere). We do have several mitigations for it though, so hopefully this won't happen any longer.
 
Top Bottom