remy / jsonbin

A personal JSON store as a RESTful service
https://jsonbin.org
395 stars 26 forks source link

Partial error E11000 when trying to log in #22

Closed paulsnar closed 7 years ago

paulsnar commented 7 years ago

So I think I logged in probably once or twice a while ago with this Github account, although on a different machine. Now I'm trying to log on via this machine, and the Github flow goes through successfully (i.e. it redirects right past it), but then I'm presented with this:

{
  "message": "E11000

jsonbin_b_1

The response seems to be streamed partially and then failing somewhere in the middle. Here are the headers.

Authenticating with a different account seems to go through fine, both first and recurring logins. I can try discarding the existing Github authentication later, if that might help.

remy commented 7 years ago

Are you able to replicate this? I just tried an incognito window and it was fine - so it's either the mongo server bailing as a one off or something else.

I can't actually replicate this at all at the moment… is there anything else perhaps?

paulsnar commented 7 years ago

I can replicate 100% (or so it seems). That's exactly why I mentioned a different account - this particular error appears to be tied to mine.

remy commented 7 years ago

Okay, I've got the error in a loggly log. I'll debug later this afternoon. It's trying to re-insert a record for you.

remy commented 7 years ago

I don't have a full solution just yet, but if you can repeat your test, I can capture a bit more debugging to help me understand how it's throwing the error.

The logic in the code looks fine, but obviously there's an edge case that I can't see.

paulsnar commented 7 years ago

Just tried once again, and also the error is now complete:

{
  "message": "E11000 duplicate key error index: jsonbin.users.$username_1 dup key: { : \"paulsnar\" }",
  "status": 500
}
remy commented 7 years ago

Ta!

remy commented 7 years ago

I should have added that the detailed logging was in loggly (obviously I don't want to expose any internals).

remy commented 7 years ago

Can you give it another try now? I've made a change to your db record which I think is the cause (I think somehow your githubId got stored as an int instead of string, so it tries to re-insert it after failing to find you, but then throws the dup key error).

paulsnar commented 7 years ago

Appears to be fixed!

remy commented 7 years ago

Sweet. I found two other users with the same problem, I've pushed a change that always ensures the user's github id is always stored as a string.