New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DUPLICATE_USER on Single Sign On #3061
Comments
It's the case sometimes when a user who already has an account with another login method tries to authenticate with SSO. It shouldn't be a race because that query that tries to insert the user is a I'd check to see if there's already a user with the same ID as the one being created via SSO. |
It is strange because I reproduced this problem locally, where there was only the admin user and the new user who was registering. So there was no possibility that the user already existed with the same ID. PS. After authenticating, even giving error 500 the user was successfully registered. |
If you were able to reproduce locally, can you try again with our |
I was able to track some users queries that were executed on mongo when the errors happened: Edit: I think the log is no longer needed from that information, right? {
"op" : "query",
"ns" : "coral.users",
"command" : {
"find" : "users",
"filter" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"profiles" : {
"$elemMatch" : {
"type" : "sso",
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
}
},
"limit" : 1,
"singleBatch" : true,
"batchSize" : 1,
"returnKey" : false,
"showRecordId" : false,
"lsid" : {
"id" : UUID("ce88890e-5302-4743-8976-d4798b73444e")
},
"$db" : "coral"
},
"keysExamined" : 0,
"docsExamined" : 0,
"cursorExhausted" : true,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
},
"nreturned" : 0,
"responseLength" : 84,
"protocol" : "op_msg",
"millis" : 0,
"planSummary" : "IXSCAN { tenantID: 1, profiles.id: 1, profiles.type: 1 }",
"execStats" : {
"stage" : "CACHED_PLAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"inputStage" : {
"stage" : "LIMIT",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"limitAmount" : 1,
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"profiles" : {
"$elemMatch" : {
"$and" : [
{
"id" : {
"$eq" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
},
{
"type" : {
"$eq" : "sso"
}
}
]
}
}
},
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 0,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"tenantID" : 1,
"profiles.id" : 1,
"profiles.type" : 1
},
"indexName" : "tenantID_1_profiles.id_1_profiles.type_1",
"isMultiKey" : true,
"multiKeyPaths" : {
"tenantID" : [],
"profiles.id" : [
"profiles"
],
"profiles.type" : [
"profiles"
]
},
"isUnique" : true,
"isSparse" : false,
"isPartial" : true,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"tenantID" : [
"[\"459604f9-3b2d-4815-ae56-437105e3d7c3\", \"459604f9-3b2d-4815-ae56-437105e3d7c3\"]"
],
"profiles.id" : [
"[\"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\", \"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\"]"
],
"profiles.type" : [
"[\"sso\", \"sso\"]"
]
},
"keysExamined" : 0,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0
}
}
}
},
"ts" : ISODate("2020-07-31T18:07:44.079Z"),
"client" : "172.17.0.1",
"allUsers" : [],
"user" : ""
} {
"op" : "query",
"ns" : "coral.users",
"command" : {
"find" : "users",
"filter" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"profiles" : {
"$elemMatch" : {
"type" : "sso",
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
}
},
"limit" : 1,
"singleBatch" : true,
"batchSize" : 1,
"returnKey" : false,
"showRecordId" : false,
"lsid" : {
"id" : UUID("6cc21ae8-8902-42c6-b566-ffd8b8066ff6")
},
"$db" : "coral"
},
"keysExamined" : 0,
"docsExamined" : 0,
"cursorExhausted" : true,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
},
"nreturned" : 0,
"responseLength" : 84,
"protocol" : "op_msg",
"millis" : 0,
"planSummary" : "IXSCAN { tenantID: 1, profiles.id: 1, profiles.type: 1 }",
"execStats" : {
"stage" : "CACHED_PLAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"inputStage" : {
"stage" : "LIMIT",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"limitAmount" : 1,
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"profiles" : {
"$elemMatch" : {
"$and" : [
{
"id" : {
"$eq" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
},
{
"type" : {
"$eq" : "sso"
}
}
]
}
}
},
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 0,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"tenantID" : 1,
"profiles.id" : 1,
"profiles.type" : 1
},
"indexName" : "tenantID_1_profiles.id_1_profiles.type_1",
"isMultiKey" : true,
"multiKeyPaths" : {
"tenantID" : [],
"profiles.id" : [
"profiles"
],
"profiles.type" : [
"profiles"
]
},
"isUnique" : true,
"isSparse" : false,
"isPartial" : true,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"tenantID" : [
"[\"459604f9-3b2d-4815-ae56-437105e3d7c3\", \"459604f9-3b2d-4815-ae56-437105e3d7c3\"]"
],
"profiles.id" : [
"[\"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\", \"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\"]"
],
"profiles.type" : [
"[\"sso\", \"sso\"]"
]
},
"keysExamined" : 0,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0
}
}
}
},
"ts" : ISODate("2020-07-31T18:07:44.079Z"),
"client" : "172.17.0.1",
"allUsers" : [],
"user" : ""
} {
"op" : "command",
"ns" : "coral.users",
"command" : {
"findAndModify" : "users",
"query" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"profiles" : {
"$elemMatch" : {
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"type" : "sso"
}
}
},
"new" : false,
"remove" : false,
"upsert" : true,
"update" : {
"$setOnInsert" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"tokens" : [],
"ignoredUsers" : [],
"status" : {
"username" : {
"history" : [
{
"id" : "3ce57899-7a65-4780-8e05-cb557c3cb447",
"username" : "my-username",
"createdBy" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"createdAt" : ISODate("2020-07-31T18:07:44.050Z")
}
]
},
"suspension" : {
"history" : []
},
"ban" : {
"active" : false,
"history" : []
},
"premod" : {
"active" : false,
"history" : []
}
},
"notifications" : {
"onReply" : false,
"onFeatured" : false,
"onModeration" : false,
"onStaffReplies" : false,
"digestFrequency" : "NONE"
},
"moderatorNotes" : [],
"digests" : [],
"createdAt" : ISODate("2020-07-31T18:07:44.050Z"),
"commentCounts" : {
"status" : {
"APPROVED" : 0,
"NONE" : 0,
"PREMOD" : 0,
"REJECTED" : 0,
"SYSTEM_WITHHELD" : 0
}
},
"username" : "my-username",
"role" : "COMMENTER",
"ssoURL" : null,
"badges" : null,
"email" : "email@email.com",
"emailVerified" : true,
"profiles" : [
{
"type" : "sso",
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"lastIssuedAt" : ISODate("2020-07-31T18:03:46.000Z")
}
],
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
},
"lsid" : {
"id" : UUID("6cc21ae8-8902-42c6-b566-ffd8b8066ff6")
},
"$db" : "coral"
},
"keysExamined" : 0,
"docsExamined" : 0,
"nMatched" : 0,
"nModified" : 0,
"upsert" : true,
"keysInserted" : 25,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 98,
"protocol" : "op_msg",
"millis" : 0,
"planSummary" : "IXSCAN { tenantID: 1, profiles.id: 1, profiles.type: 1 }",
"execStats" : {
"stage" : "UPDATE",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"nMatched" : 0,
"nWouldModify" : 0,
"nInvalidateSkips" : 0,
"wouldInsert" : true,
"fastmodinsert" : false,
"inputStage" : {
"stage" : "CACHED_PLAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 0,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"profiles" : {
"$elemMatch" : {
"$and" : [
{
"id" : {
"$eq" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
},
{
"type" : {
"$eq" : "sso"
}
}
]
}
}
},
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 0,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"tenantID" : 1,
"profiles.id" : 1,
"profiles.type" : 1
},
"indexName" : "tenantID_1_profiles.id_1_profiles.type_1",
"isMultiKey" : true,
"multiKeyPaths" : {
"tenantID" : [],
"profiles.id" : [
"profiles"
],
"profiles.type" : [
"profiles"
]
},
"isUnique" : true,
"isSparse" : false,
"isPartial" : true,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"tenantID" : [
"[\"459604f9-3b2d-4815-ae56-437105e3d7c3\", \"459604f9-3b2d-4815-ae56-437105e3d7c3\"]"
],
"profiles.id" : [
"[\"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\", \"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\"]"
],
"profiles.type" : [
"[\"sso\", \"sso\"]"
]
},
"keysExamined" : 0,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0
}
}
}
},
"ts" : ISODate("2020-07-31T18:07:44.085Z"),
"client" : "172.17.0.1",
"allUsers" : [],
"user" : ""
} {
"op" : "command",
"ns" : "coral.users",
"command" : {
"findAndModify" : "users",
"query" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"profiles" : {
"$elemMatch" : {
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"type" : "sso"
}
}
},
"new" : false,
"remove" : false,
"upsert" : true,
"update" : {
"$setOnInsert" : {
"tenantID" : "459604f9-3b2d-4815-ae56-437105e3d7c3",
"tokens" : [],
"ignoredUsers" : [],
"status" : {
"username" : {
"history" : [
{
"id" : "37713392-495a-436c-93b2-d38485c60f8d",
"username" : "my-username",
"createdBy" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"createdAt" : ISODate("2020-07-31T18:07:44.057Z")
}
]
},
"suspension" : {
"history" : []
},
"ban" : {
"active" : false,
"history" : []
},
"premod" : {
"active" : false,
"history" : []
}
},
"notifications" : {
"onReply" : false,
"onFeatured" : false,
"onModeration" : false,
"onStaffReplies" : false,
"digestFrequency" : "NONE"
},
"moderatorNotes" : [],
"digests" : [],
"createdAt" : ISODate("2020-07-31T18:07:44.057Z"),
"commentCounts" : {
"status" : {
"APPROVED" : 0,
"NONE" : 0,
"PREMOD" : 0,
"REJECTED" : 0,
"SYSTEM_WITHHELD" : 0
}
},
"username" : "my-username",
"role" : "COMMENTER",
"ssoURL" : null,
"badges" : null,
"email" : "email@email.com",
"emailVerified" : true,
"profiles" : [
{
"type" : "sso",
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755",
"lastIssuedAt" : ISODate("2020-07-31T18:03:46.000Z")
}
],
"id" : "f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755"
}
},
"lsid" : {
"id" : UUID("ce88890e-5302-4743-8976-d4798b73444e")
},
"$db" : "coral"
},
"keysInserted" : 1,
"writeConflicts" : 1,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"exception" : "E11000 duplicate key error collection: coral.users index: tenantID_1_id_1 dup key: { : \"459604f9-3b2d-4815-ae56-437105e3d7c3\", : \"f:1111a1fb-002f-489e-b9c2-d57aba0ae494:467a1f51-1fc2-41c8-93ff-9c223fc0b755\" }",
"exceptionCode" : 11000,
"responseLength" : 280,
"protocol" : "op_msg",
"millis" : 17,
"planSummary" : "IXSCAN { tenantID: 1, profiles.id: 1, profiles.type: 1 }",
"ts" : ISODate("2020-07-31T18:07:44.103Z"),
"client" : "172.17.0.1",
"allUsers" : [],
"user" : ""
} |
It does seem like a race against that index. This operation is involving two unique indexes, one with: {
"tenantID": 1,
"id": 1
} And another with: {
"tenantID": 1,
"profiles.id": 1,
"profiles.type": 1
} Check to see that both these indexes in MongoDB are not background and are unique with |
We'll triage this issue and get it patched! Thanks for the details! |
Thank you @wyattjoh :) |
Not sure if this is related, but I'm getting a Context: I maintain a private fork of Coral because I need to have slightly tweeked permission setting. Its a 2 line diff from the main branch. Periodically, I pull in the latest. I did today and started seeing this error. {
"error": {
"id": "...",
"code": "DUPLICATE_EMAIL",
"type": "INVALID_REQUEST_ERROR",
"message": "Specified email address is already in use."
}
} |
That doesn't seem related @zekenie. Ensure there is no other user accounts with the same email address (with a email based auth) that this would conflict with. |
Fixed in #3068 |
Hello, we are using SSO authentication, but the first time the user authenticates, when he should be created in the database, the following error is almost always thrown:
As two requests are made, I believe it can be a concurrency issue. Both requests may be trying to create the user at the same time.
The text was updated successfully, but these errors were encountered: