News:

Wondering if this will always be free?  See why free is better.

Main Menu

Database error message for "like": Duplicate entry

Started by Julius_2000, January 31, 2023, 12:23:32 PM

Previous topic - Next topic

Julius_2000

Hi all,

looking through the error log I noticed this entry:

Database Error: Duplicate entry '30891-msg-33' for key 'smf_user_likes.PRIMARY'
When I try to open the link to that message from the log, I get
QuoteSession verification failed. Please try logging out and back in again, and then try again.

It's the first time this occurred. What does it mean? Is this something to be worried about or just minor hiccup?


Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Julius_2000

Dang, stupid me has cleared the log. The message itself is as I posted above. SMF pointed to a likes.php or something among those lines and showed the message link which I couldn't open because of the session verification issue mentioned above. I'll try and comb through the php to see whether I can spot the specific line. Don't know why I didn't post this in the first place. Sorry.

Doug Heffernan

Quote from: Julius_2000 on January 31, 2023, 12:23:32 PMDatabase Error: Duplicate entry '30891-msg-33' for key 'smf_user_likes.PRIMARY'

This error usually happens because there is already an existing value for the column which has been defined as PRIMARY KEY.

Kindred

Quote from: Doug Heffernan on February 01, 2023, 07:20:48 AM
Quote from: Julius_2000 on January 31, 2023, 12:23:32 PMDatabase Error: Duplicate entry '30891-msg-33' for key 'smf_user_likes.PRIMARY'

This error usually happens because there is already an existing value for the column which has been defined as PRIMARY KEY.

Yup.... but that should not happen in the core product's like system without something else happening to break it.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Steve

DO NOT pm me for support!

Julius_2000

Hi Steve,

it has not occured again but I can't say for sure if it's resolved since I don't know why it happened. Unfortunately I prematurely cleared the log before taking comprehensive notes.

Steve

Okay, I'll mark it solved for now but if the issue returns, by all means, mark it as unsolved.
DO NOT pm me for support!

Julius_2000

Alright, it happened one more time. This time I'll preserved the log ;)


Off topic: By the way, has the attachment section been reworked? It looks a bit different than I remember.


Arantor

I think you have a user double clicking the like button and it trying to insert the same like twice.

I don't think it's a huge concern, but it should be tidied up.


GL700Wing

#11
Quote from: Arantor on April 20, 2023, 07:18:06 AMI think you have a user double clicking the like button and it trying to insert the same like twice.

I don't think it's a huge concern, but it should be tidied up.
Double-clicking causes this error because 'insert' statements are used instead of 'ignore' statements (the same issue was reported last year for the 'Thanks for SMF 2.1 mod which I cloned from the native SMF 2.1 'Likes' system).
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Arantor

Yes, I know, at the time I wrote the above reply I was on mobile and couldn't check if the *other* part of the situation was handled correctly, namely the count of likes on a message.

When I first wrote likes in 2.1 it did, but I also knew it had been massively reworked since I did and wasn't sure if you'd end up with a different problem for just switching insert for ignore where the likes count would get +2 instead of +1, but actually my original implementation and the subsequent restructure both get this correct, forcing a recount rather than just trusting a +1 is appropriate.

shawnb61

I cannot reproduce this.

The Like button toggles the state...  If you press it again, it doesn't like it again, it unlikes it...

If you press the like button many times in sequence, even rapidly, it just goes back and forth between liked & not liked. 
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Arantor

It's a race condition. On your machine the roundtrip is fast enough that you can't beat it.

On this server I can if I really go at it produce 403s, with the error message 'Sorry, but you're not allowed to access the file you requested.' which is I assume the net result of it here, bearing in mind that this is an SMF level error being returned to me with SMF chrome, not something further up or down the stack (e.g rate limiting

(Sorry for the alert spam but I can't like my own posts.)

shawnb61

I've tested in multiple online environments.

Can you reproduce the database duplicate key error under discussion?
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

GL700Wing

#16
Quote from: shawnb61 on April 22, 2023, 05:21:18 PMI cannot reproduce this.

The Like button toggles the state...  If you press it again, it doesn't like it again, it unlikes it...

If you press the like button many times in sequence, even rapidly, it just goes back and forth between liked & not liked. 

I couldn't reproduce it either at the time but @Steve has not reported a repeat of the problem since the code change was made.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Arantor

No, but I just proved I can reproduce *an* error in the fashion I outlined?

I personally at this point would change the insert to an insert-ignore in Likes.php and move on with my day because I can see how it could happen and I'm perfectly willing to believe on a less efficient stack than you're working with, that this kind of race condition absolutely could happen.

Advertisement: