502 errors when renaming large (by topic count) categories

Hi.
I’ve also posted here: Moving posts returns 502 bad gateway
but it seems that the error occurs in other contexts. I can’t rename a category:

Js console:
image

Same in safe-mode (I don’t have custom themes or plugins anyway, except data-explorer), version 2.6.0.beta2
My server is on Ubuntu 18, has 4 vCPU, 8 GB ram, 160 GB disk space.

3 Likes

Does it take a long time for the error to surface? I think you’re running into a timeout because of a heavy query.

1 Like

20-30 seconds maybe? Also, it doesn’t happen when renaming other categories. :thinking:

edit: also happens on my development forum (fairly strong computer with a ubuntu subsystem).

re-edit:

  1. splits by smaller batches seem to work. So Discourse doesn’t like to move more than 3000 topics, even of a more powerful server (I upscaled to a 16 vCPU / 32 GB). So I guess that this issue is different from renaming my categories. I still couldn’t rename the category.

  2. I created a new category B (which I can rename at will), moved all the topics from the category A (which I can’t rename) to the category B: then I can’t rename category B anymore, and I can rename the category A.
    I tried to rename my categories, choosing a category with more posts in it each time. Category with more content (more posts, larger topics) seems to take more time to be renamed.

There are 2 categories that I can’t rename (seems to take too much time indeed…):
image

I can rename Public profile messages, which contain only topics without replies.

30 seconds is the nginx timeout, so that makes sense. It just needs more time than that.
If I were you I would try this from a rails console.

I thought doing it this way, but I wasn’t sure it would be safe: I wonder why it would take that much time just to rename a category title in Discourse :thinking:
Does it need to check stuff I don’t think about?

Apparently :slight_smile:
I guess it might be recalculating some stats. What you could do is connect to Postgres and run something like

SELECT pid, age(query_start, clock_timestamp()), usename, query 
FROM pg_stat_activity 
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' 
ORDER BY query_start desc;

to see what it is what is taking so long.

Thank you!
I’m not familiar with that though. Should I run this query while Discourse is trying to change the category name?

Yes, it will show you the currently running queries, so you should run it while waiting. You have 30 seconds :wink:

2 Likes

I ran the query about 10 seconds after trying to change the category name, and here’s what it returns:

I see nothing weird? :thinking:

I see a very trivial query (UPDATE categories...) that looks like it is taking up 13 seconds already…
What happens if you run it manually?

EDIT if this is an imported forum, it might help to backup and then restore it.

Since I have the same issue on my development install on my home computer, I tried on my dev forum.

I tried to change the category name through Discourse interface. The error I’ve shown in my first post occured and my ram was filled up:
image

Your query shows:

I tried updating from the rails console,
Tried these two commands:

ActiveRecord::Base.connection.execute("UPDATE categories SET name = 'General Discussion', topic_template = '', sort_order = '', default_view = '', read_only_banner = '', name_lower = 'general_discussion', updated_at = '2020-09-16 13:36:50.014192' WHERE categories.id = 21")
Category.where(id: 21).update(name: "General")

Both worked like a charm.

That’s… interesting… :thinking:

Update: I tried to rename a category on my other, live forum (different data/server/os/etc, but same Discourse version).

Changing a category name is slow (~10s). I tried multiple times and also encountered a 502 error once.

I feel like this is an issue from Discourse maybe related to a recent update? :thinking:
Both forums use 2.6.0.beta2.

Can someone try to change a category name (a category with thousands, or tens of thousands topics) on their own forum, with the same Discours version to see if it is slow or generates a 502?

2 Likes

Did renaming categories with a large number of topics work fast for you in previous Discourse version?

I don’t remember having a 502 error on my previous forum (which was also imported), but I haven’t renamed a category since the import 3 years ago. I don’t remember if renaming a category was slow.
As for my new, larger forum, it was imported on the Discourse’s version I’m mentioning so I can’t compare with an older version.

1 Like

Just a correction about this: I think I previously did Category.where(id: 21).update(name: "General") for a category from which I moved the topics out or something like that, because I had to use this command multiple times on various categories right now, and it appears that the command duration is proportional to the number of posts in the target category.
So basically, it’s the same issue as when I update the category from the interface, except that it won’t timeout in the command line.

It took more maybe one minute for a category with more than 30000 topics, more than, 30 seconds on a topic with more than 15000 topics, and it was fast for categories with few topics.

1 Like

Our forum has been getting increasingly error-prone over the last 6 months. I’ve just doubled our server resources (16 CPU’s, 64GB RAM) and while it runs much better, I’ve found a reproducible error.

Just trying to rename one category gives a 502 error every time.

2 Likes

Did you adjust the settings in the app.yml accordingly?

You should look in the logs to see if you get a hint. Is there something special about that category? Perhaps you have a database index corruption?

2 Likes

Yep!

Is that just looking at forumwebsite.com/logs? I don’t see errors that specifically relate to the action of renaming a category.

I see lots of things in Info, but again nothing specific to the action.

Should I be trying to clear any errors?

2 Likes

you can look at /admin/logs (or something like that) in the web interface and something like

tail -f /var/discourse/shared/standalone/logs/rails/production.log

That’s from memory and typed with fingers, so I’d recommend using some tab-completion. :slight_smile:

4 Likes