Traewelling / traewelling

Free check-in service to log your public transit journeys
https://traewelling.de
GNU Affero General Public License v3.0
224 stars 43 forks source link

500 when accepting follow requests #2651

Open HerrLevin opened 1 month ago

HerrLevin commented 1 month ago

Describe the bug

In very rare cases it's possible to provoke an error 500 (AlreadyFollowingException) when accepting a follow request

Steps to reproduce

This cannot easily be reproduced without manipulating the database.

  1. Table follows

    id|user_id|follow_id|created_at             |updated_at             |
    --+-------+---------+-----------------------+-----------------------+
    1|      1|        2|2024-04-19 13:07:10.000|2024-04-19 13:07:10.000|
  2. Table follow_requests

    id|user_id|follow_id|created_at             |updated_at             |
    --+-------+---------+-----------------------+-----------------------+
    1|      1|        2|2024-04-19 12:00:01.000|2024-04-19 12:00:01.000|
  3. Accept follow-reqeust

Browser console logs

No response

Browser

No response

HerrLevin commented 1 month ago

Idea: try/catch around the follow acceptance and just remove the follow request if THIS exception occurs

MrKrisKrisu commented 1 month ago

I cannot find the cause of your problem. We have two endpoints APIv1 and legacy frontend. Both Endpoints catches the AlreadyFollowingException and don't return HTTP 500 then.

https://github.com/Traewelling/traewelling/blob/a55c811bff153a482eb68f080984ae721f9a5887/app/Http/Controllers/API/v1/FollowController.php#L63-L64

https://github.com/Traewelling/traewelling/blob/a55c811bff153a482eb68f080984ae721f9a5887/app/Http/Controllers/FrontendUserController.php#L78-L79