Ghost Update: ECONNREFUSED ::1:3306 + Error code 502

Just to share what problem I got after update of Ghost and Ubuntu 22.04

What happened:

  1. Update of Linux (Ubuntu 22.04.3 LTS)
apt-get update
apt-get upgrade
  1. Update of node:
  1. Ghost update

Ghost-CLI version: 1.25.3
5.66.0 → 5.69.0

Error during the update and roleback

The problem

Ghost was starting but didn’t work.
After several attempts I got that Ghost couldn’t connect with the database with errors:

Message: connect ECONNREFUSED ::1:3306

and

Bad gateway Error code 502

Fix

I found fix here:

So what you need to do is:

sudo nano /etc/hosts

Remove/comment this line from the file: - ::1

127.0.1.1 ubuntu-8gb-ash-1 ubuntu-8gb-ash-1
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
#::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

This seems to be a quick workaround if anyone face it.
Still checking what could be the reason and should be done.

2 Likes

@daniellockyer There are multiple reports recently of the same kind of IPv6 related breakage on what looks like a supported stack.

The other report recently was:

The trigger seems to be the same: users ran an update of either Ghost or Ubuntu and some connections start defaulting to IPv6 instead of IPv4. In turn, this fails if the right entries aren’t in /etc/hosts.

I’m not sure if:

  1. This should be considered a regression, so Ghost should just try to default to IPv4 for now because it doesn’t need an IPv6 connection on localhost.
  2. The behavior was intentional and desirable, so the “fix” is update some documentation.

I’m guessing it’s #1, and there’s some place in the Ghost stack where it can be configured to explicitly keep using IPv4 for localhost connections.

1 Like

I think it’s a breaking change between node16 and node18. Further reading:

@vikaspotluri123 I agree.

The question is whether it should also be a breaking change for Ghost, or whether Ghost should smooth over the difference.

I imagine nearly everyone connecting from Ghost to MySQL via a “localhost” lookup supports IPv4 lookups and and likely already using IPv4 resolution.

For the less common case with remote databases, I’m less sure what’s ideal.

There are probably a lot more domains that have IPv4 resolution setup but not IPv6, then the other way around.

This is a place where some telemetry would be useful, to better understand how many sites break Ghost forced the resolution back to IPv4 for all DNS lookups for now. I expect it may fix more than it would break.

Yeah, I guess this is a “bug” that was introduced when Ghost added support for node18. Now that node16 is EOL’d, I guess a lot more people are running into this issue.

1 Like

Immediately, a note could be added to not upgrade to node 18 till this is sorted out, or have upgrade docs which mention the issue.

1 Like

thanks for posting this! I could not figure out why my first ghost prod install was not working and thought I was going crazy

1 Like

Had the same problem, solved by removing that line. Is this a long term fix or there is gonna be something else to do in the future?

This should be a long term fix, assuming major distro updates don’t override your hosts (you have to explicitly perform a major distro upgrade, and explicitly tell the upgrade utility to pick the distro-suggested version over your own)

2 Likes