Willekeurige 404-fouten bij het bewerken van berichten

AI-generated summary

Nacho_Caballero reported random 404 errors when editing replies in their Discourse forum, where the app sometimes sends a PUT request to /post_replies/:post_id (which returns 404) instead of the correct /posts/:post_id. The issue disappears after refreshing the page. After multiple attempts to debug, Nacho_Caballero discovered a consistent reproduction method: disabling “enable filtered replies view”, then navigating via reply arrows to the original post and attempting to edit. This triggered the 404 reliably. pmusaraj confirmed the steps were helpful and submitted a fix via PR #12504. Nacho_Caballero noted how simple the fix was, and codinghorror thanked them for the detailed reproduction steps, which enabled a quick resolution. The bug occurred across versions including 2.7.0.beta2 and affected both old and new posts randomly, with no server-side logs indicating issues. Browser console logs showed failed requests to /post_replies and successful ones to /posts after refresh, suggesting a frontend routing or state issue in EmberJS, as Falco speculated.

I’ve been getting random 404 errors when editing replies in my forum.

When edits work, they send a PUT request to the endpoint /posts/:post_id with a 200 response.

But when they don’t work, I can see in the developer tools a PUT request to /post_replies/:post_id that returns a 404. When I refresh the page, the errors go away and I’m able to save the edit correctly (via /posts/:post_id, the :post_id doesn’t change).

I’m not sure if there is a special condition that could make /posts turn into /post_replies by mistake or if it’s a different problem. I recently quadrupled my server’s RAM and I haven’t seen anything weird in the logs.

Any help is appreciated.

2 likes

I continue to get these random errors when trying to save an edit for other people’s posts. It happens with both old and new posts, but always randomly:

And it goes away when I refresh the page and save the edit:

I’m on the latest version and can confirm this is still happening: trying to save an edit on other another user’s post randomly triggers a dialog box with a not_found message:

The requested URL or resource could not be found.

If I reload the page and press the “Save Edit” button again, the error goes away and the edit is saved.

Those two requests are getting PUT to different URLs.

Right. But why? I’m pressing the same “Save Edit” button in the same post. The only difference is a page refresh

Maybe try checking the browser backtrace next time it happens? Since it’s hitting different endpoints it may be going via different methods in the EmberJS app.

1 like

@Falco It just happened again. This is all I see when I open the console after I get the error:

image

And if I try saving again with the console open:

Then I refresh the page and it lets me edit:

image

This is the path of the initiator (VM73:1 Script):

1 like

I just updated to 2.7.0.beta2 and it’s still happening:

  • Try to edit post reply 47994
  • PUT https://mydomain.com/post_replies/47994 => 404 The requested URL or resource could not be found. In console: Failed to load resource: the server responded with a status of 404 () /post_replies/47994:1
  • Reload the page
  • Try to edit post reply 47994
  • PUT https://mydomain.com/posts/47994 => 200 success

If there’s any other information that would help debug it, I’d be happy to provide it.

This happened 3 times today in less than an hour :sweat_smile:

Is there anything else I could do to help track this bug down?

@Falco I finally figured out how to consistently reproduce this bug:

  1. Disable enable filtered replies view
  2. Click on the arrow on a reply:
  3. Click on the arrow to jump to the original message: image
  4. Click on the edit icon:
  5. Make a change and hit “Save changes”. You’ll get a dialog box saying that the URL or resource wasn’t found (404).
4 likes

Thanks @Nacho_Caballero, the specific steps were very helpful. I have a PR up with a fix: FIX: 404 error when editing an expanded reply by pmusaraj · Pull Request #12504 · discourse/discourse · GitHub

7 likes

No problem! Such an easy fix :sweat_smile:

3 likes

As usual thank you for your patience with us Nacho – when you provide very detailed repros we can almost always whip up a fix!

4 likes