DiscourseTagging.tag_topic_by_names never returns on some combinations of tags

This is verging on bug

DiscourseTagging.tag_topic_by_names(current_topic, Guardian.new(tagging_user), tag_name_short_list, append: true)

I’m trying to understand why, but when I call this library function with some combinations of tags, it never returns.

When it works, it is almost instantaneous.

A single tag addition can cause it to completely “freeze”.

I can reproduce this in the rails console.

it is most odd!

When I cancel the operation I notice it appears to be in the middle of some pg work?:

from /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-mini-profiler-3.1.1/lib/patches/db/pg.rb:110:in exec

I’ll try to enrich this report asap.

See several locks in the database:

(This is just a few. There were many, many more!)

I’ve restarted the container, which cleared the locks. Will see if I can reproduce again.