publiclab / plots2

a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! :balloon:
https://publiclab.org
GNU General Public License v3.0
956 stars 1.83k forks source link

Error in WikiController: AbstractController::DoubleRenderError: Render and/or redirect were called multiple times in this action. #9328

Closed sentry-io[bot] closed 3 years ago

sentry-io[bot] commented 3 years ago

Sentry Issue: PLOTS2-16F

AbstractController::DoubleRenderError: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
  app/controllers/wiki_controller.rb:469:in `comments'
    render :show
...
(110 additional frame(s) were not displayed)
jywarren commented 3 years ago

Hi @noi5e I noticed this error in Sentry after the recent publish to live site. I was wondering if it could be related to some of your new code?

https://sentry.io/share/issue/d051f88028e74c839ac869162ea7eee7/

It apparently affects this page: https://publiclab.org/wiki/betelgeuse-star-%09spectrum/comments

I haven't checked if all wiki comment pages are affected. The URL there looks weird though so maybe that's the issue. Would yo mind taking a look? Thank you!

noi5e commented 3 years ago

@jywarren Sure thing! Will take a look today

noi5e commented 3 years ago

@jywarren I think this is a URL issue. https://publiclab.org/wiki/betelgeuse-star-%09spectrum/comments leads to a 404

If you look at that URL turns out that %09 is HTML encoding for a horizontal tab. 🤔 That's weird, wonder how that got in there.

If you take out the %09 it does lead to a valid page: https://publiclab.org/wiki/betelgeuse-star-spectrum/comments

Here's the wiki#comments method that appears in the stacktrace: https://github.com/publiclab/plots2/blob/0908bfda7ef2462e6b6b61fd8c4654d60f3c3ada/app/controllers/wiki_controller.rb#L467-L470

That means that wiki#show is called right before wiki's :show template is rendered right?

Here's wiki#show for good measure: https://github.com/publiclab/plots2/blob/0908bfda7ef2462e6b6b61fd8c4654d60f3c3ada/app/controllers/wiki_controller.rb#L21-L86

I think this is what might be happening:

  1. For some reason, sentry is trying to visit betelgeuse-star-%09spectrum, a wiki ID that doesn't exist in the DB
  2. wiki#comments calls the wiki#show method
  3. wiki#show tries to find the ID, but fails

It could be something about the conditional rendering in wiki#show that causes a render or redirect to be called. This would be on top of the render :show that wiki#comments subsequently calls, which would lead to Sentry's particular error. I don't know this for sure, I would have to sit down and closely read the conditionals in wiki#show to be sure... Or brush up on Rails's controller conventions as well. What do you think?

noi5e commented 3 years ago

@jywarren Also check this out, if I visit /wiki/pokemon/comments in development (which doesn't exist for me locally), I get the same error:

Screen Shot 2021-03-18 at 11 05 34 AM

Interestingly, visiting just /wiki/pokemon (no /comments), leads here, with no error messages:

Screen Shot 2021-03-18 at 11 08 04 AM

So it seems like it's something to do with how wiki#comments is called for wiki IDs that don't exist.

Also, I'm thinking this isn't caused by changes I made in the codebase, but can dig a little further if we need to confirm 😊. I haven't really touched the wiki or comment controllers. I did make some changes to comment controllers in react-comments, but that hasn't been merged to main yet.

jywarren commented 3 years ago

OK, i think we are OK then, i'll close this. We often get some uptick in issues after publishing latest code, so I try to be vigilant but this just seems like someone accidentally entered misencoded text as a URL or maybe a bot did it...

Thank you so much for looking into it. 🎉