0

I'm currently investigating an issue on one of my web apps, a user was somehow able to create a duplicate record when he registered. When inserting the user details into the DB I save the registered date, the date on these 2 entries are exactly the same up to the split seconds. enter image description here

On the form's 'phone number' field, I have a onchange event that hits an endpoint to check if that phone number already exists, and the user cannot save/register if so. < 1st layer I don't know how it got bypassed.

secondly, I have this check in the async method that saves the user: enter image description here

also don't know how that got bypassed...

my question isn't related to code or any errors, it's more of how can I further investigate this? or what can possibly cause this issue, it happens every now and again...

4
  • Even the milliseconds are same? How exactly is that date generated? If they're fraction of seconds apart then it is possible that the request got submitted twice, the duplicate checks were passed, then both requests completed by creating a record. Commented Apr 25, 2023 at 14:30
  • You can add a unique index covering the relevant identity columns, which will then reject the duplicate and give you insight into how it is happening. Commented Apr 25, 2023 at 15:01
  • If you require the phone number to be unique, you should use a unique constraint in the database. You cannot rely on manual checks for things like this. You need to use the consistency guarantees provided by your database, assuming an ACID database and not any eventual consistency model. Commented Apr 25, 2023 at 15:29
  • Hi all, thanks for the comments, and yes the date registered for both records is exactly the same. I'll edit the question and add a screen snip. I do have a GUID that is the ID of the user's record, but this is only generated when the record is inserted... hence I check for the phone number.. as this will be unique 99% of the time. I'm lost on what steps to take to further investigate this... the date registered is simply DateTime.Now in .NET Commented Apr 26, 2023 at 5:24

1 Answer 1

0

I found the culprit. Double-clicking the submit button creates duplicate records, how this is a thing, I don't know...

My solution contains 2 fixes.

on the front end, I'll disable the button once clicked:

<button id="btnConfirmDetails" type="button" onclick="document.getElementById('btnConfirmDetails').disabled = true;Register();" class="btn btn-primary margin-bottom-s inherit-parent-size">Confirm</button> 

For extra protection, I will add a unique constraint to the phone number field. (EF core code first approach) Entity Framework Core add unique constraint code-first

I hope this can help someone else..

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.