If you stumbled across this blog post, you probably tried everything else available on the internet already, because let's face it, this article is hidden pretty deeep on the web.

The Problem

So you're running Ghost as a service in Swarm and you're seeing a status 500 error that looks something like this

select count(distinct posts.id) as aggregate from posts where (posts.status = 'published' and posts.page = false) - read ECONNRESET

At the date of writing this, there are no real fixes online, and since the Docker image is not maintained by Ghost, we're out of luck.

The Cause

The issue seems to be coming from the Docker swarm overlay network due to IPVS connection tracking timeout, blabla linux kernel,  IPVS L4 load balancer, ingress network bla bla bla

(it's due to a timeout with the database connection)

The Fix

Below you can find a quick and dirty fix ✔️

It's a cron job to ping your blog every 10 minutes and keep the connection alive. (make sure you're pinging a page that queries the database)

Substitute the URL with a link to your blog, and paste the snippet into your terminal.

crontab <<'EOF'
*/10 *  *  *  *     curl -s 'https://<URL_TO_YOUR_BLOG>'

To see if it's listed in your crontab you can use the command crontab -l