michael,
@michael@thms.uk avatar

Over the last few days I'm getting a lot of errors in my Mastodon UI.

In my web server logs I get this error a lot:

ActiveRecord::ConnectionTimeoutError (could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use)

Any thoughts on how to resolve this?

michael,
@michael@thms.uk avatar

Still not been a me to fix this. Here is what I’ve tried:

Played with the max_client_conn and default_pool_size settings in pgbouncer

Played with DB_POOL in .env.production

Turn off pgbouncer

Restated pgbouncer

Restarted all mastodon processes.

I am out of ideas

(Single user instance running on a fairly low-spec machine running glitch-soc, by the way, but has been running stable until the weekend (when I last merged in from glitch-soc/main)

I’m currently restarting mastodon-web every 10 min which sort of just about keeps it alive but is clearly not a solution…

virtulis,
@virtulis@loud.computer avatar

@michael my first guess would be some kind of long-running queries. Have you checked for those?

There's some kind of PgHero thing in the masto admin UI, or you can always select * from pg_stat_activity where state != 'idle';

michael,
@michael@thms.uk avatar

@virtulis yep. Checked that. Nothing.

rolle,
@rolle@mementomori.social avatar

@michael Have you tried with Vanilla Mastodon? Does it work with that? That would be my first try. Usually errors happen when using some code or branch that has a mistake. I have no clue about glitch-soc but there would be my first bet.

I myself have been having to revert back to a commit or even do a hard reset to vanilla couple of times because of a faulty merge or some literal glitch in my changes. Sometimes you just have to start over or go back a bit, if nothing else fixes it.

michael,
@michael@thms.uk avatar

@rolle yeah, I think I’ll be trying to revert that merge today, to see if that helps.

paul,
@paul@oldfriends.live avatar

@rolle @michael
I can't help you much, other than I remember this error when I tried to custom tune my sidekiq processes last year.

I would debug your sidekiq settings. If this happened when you merged in from glitch-soc/main, maybe something is out of whack.

michael,
@michael@thms.uk avatar

@paul hm. Sidekiq seems to be doing fine though, and I I haven’t changed those settings in ages. 🤔

michael,
@michael@thms.uk avatar

It looks like I finally managed to resolve this by increasing postgres’ max_connections setting, together with introducing the DB_POOL setting in my Mastodon enviroment:

https://blog.thms.uk/2023/07/tweaking-postgres-mastodon?utm_source=mastodon

I have no idea why this was suddenly required, when Mastodon was running just fine previously, but it does seem to have resolved it.

Thanks everyone who tried to help me, and especially to @mwadmin for pointing me in the right direction.

xocolatl,

@michael @mwadmin
Increasing max_connections does indeed increase the amount of shared memory used, but it doesn’t come out of shared_buffers, so that advice seems ill-informed to me.

I am not saying you shouldn’t do it, I am just saying that the justification is wrong.

mwadmin,
@mwadmin@mastodon.world avatar

@xocolatl @michael The advice was to raise max_connections :-)

michael,
@michael@thms.uk avatar

@mwadmin @xocolatl yes, the idea to increase shared_buffers was mine.

Promptly reverted now 😬

michael, (edited )
@michael@thms.uk avatar

@xocolatl interesting. I may try to reduce that again, and see how that goes.

michael,
@michael@thms.uk avatar

@xocolatl I've reduced that again, and the server is running just as stable as it was before, so I've updated the post.

Thanks for the heads up!

rolle,
@rolle@mementomori.social avatar

@michael The word "timeout" itself sounds like the issue they fixed in 4.1.5.

michael,
@michael@thms.uk avatar

@rolle do you mean this one? https://github.com/mastodon/mastodon/pull/26055

That's a different thing, I'm pretty sure

rolle,
@rolle@mementomori.social avatar

@michael Yeah. OK, then I have no idea. 🤷‍♂️ I hope you get the hang of it.

admin,
@admin@hear-me.social avatar

@michael

Not an expert but having read about such postresql issues, the answer always seems to be that you need to set up connection pooling. It seems you hit the limit for the number of allowed simultaneous postgresql connections.

Are you using connection pooling? From what I read, this limit you hit is an easy limit to hit without pooling. And, of course, postgresql does not support connection pooling natively. You need to add it.

There are those much more expert than me, but here's my thoughts. Ignore if you are already using connection pooling.

Have you installed pg_bouncer? It will keep a number of connections open to the database (saves time) and lets them be shared by a number of processes simultaneously so you won't run out of connections.

There are articles that help in the non-straightforward calculation of the optimal number of shared connections.

michael,
@michael@thms.uk avatar

@admin Yes, good points. I already got pgbouncer installed, and it should pool connections.

But I'm far more familiar with MySQL than so I'm a bit lost with how to proceed

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • modclub
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • cubers
  • GTA5RPClips
  • thenastyranch
  • Youngstown
  • rosin
  • slotface
  • tacticalgear
  • ethstaker
  • kavyap
  • Durango
  • anitta
  • everett
  • Leos
  • provamag3
  • mdbf
  • ngwrru68w68
  • cisconetworking
  • tester
  • osvaldo12
  • megavids
  • khanakhh
  • normalnudes
  • JUstTest
  • lostlight
  • All magazines