SocketClosedUnexpectedlyError: Socket closed unexpectedly

======== TEMPLATE BUG FORM ========

Wappler Version : 6.1.3
Operating System : Mac M1
Server Model: NodeJS
Database Type: MySQL 8
Hosting Type:

Local: Docker with Docker Redis
Staging: Docker with Docker Redis
Prod: Docker with External Managed Redis (Digital Ocean).

cloudflare managing DNS of staging and production
traefik used for ssl

Expected behavior

I should be able to deploy my working staged app to production and access the app as expected.

Actual behavior

When I try to access my app I get:

404 page not found

This error is what I receive in my Web Server Logs:

SocketClosedUnexpectedlyError: Socket closed unexpectedly
at Socket. (/opt/node_app/node_modules/@redis/client/dist/lib/client/socket.js:195:118)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at Socket.emit (node:domain:489:12)
at TCP. (node:net:301:12)

I can confirm:

  • My Redis managed server is accessible and without error
  • My app is ‘green’ in terms of deployment status, and the database etc.
  • the DNS is propagated fine so it’s not a DNS issue
  • Staged app with Redis in Docker is accessible at the URL path.

Please confirm if this setting is configured correctly for the Production target:

Hi Apple, I’m using a Managed Redis Server for prod (and this was working until the recent 1 or 2 updates).

I followed @George instructions at the bottom of this post: Setting up Managed Redis External DB for prod - having issues, please help! for configuration, which results in the configuration needing to be different to that in your image.

I use redis://redis for the Doker Redis setup.

George this is turning out to be the same issue as before now (as per the linked post that was marked as fixed) - I am now unable to receive a ‘green’ indicator on production when trying to deploy using a Managed Redis Server. I have setup Redis exactly as per your guidance in that post.

If I change from remote redis in Wappler settings to Docker, then the app deploys to production fine and without issue.

Could you check the server connect settings per target? So you have to switch the active target and then open the server connect settings and check the Redis options.

Yep I’ve done this. It’s all correct for local and staging and then prod is the remore redis connection string as per your guidance.

Also looked at the actual project json file to make sure all the connection details are correct.

maybe all your connection settings are fine, but you are using different Redis server versions. I found a topic about this:

Can you edit the file lib/setup/config.js:

Search for:

const client = createClient(typeof config.redis == 'object' ? config.redis : {
  url: config.redis === true ? 'redis://redis' : config.redis,
  socket: { connectTimeout: 60000 },
  pingInterval: 10000,
});

change it to:

const client = createClient(typeof config.redis == 'object' ? config.redis : {
  url: config.redis === true ? 'redis://redis' : config.redis,
  socket: { connectTimeout: 60000 },
  pingInterval: 1000,
});

Another thing you can try is:

Search for:

client.connect().catch(err => {
  // we don't want to crash the server if redis is not available
});

global.redisClient = client;

change it to:

client.connect().then(() => {
  global.redisClient = client;
}).catch(err => {
  // we don't want to crash the server if redis is not available
});

Let me know if one of the 2 changes worked. The error is when the connection got closed due to a timeout or the connection is not available yet. The first change in the previous post sets a smaller ping inteval, this should keep the connection alive (normally the 10000 (10s) should be okay). The second change only sets the global redisClient after it is connected, this should prevent using the redis client when it isn’t yet connected.

Hi @patrick - I’ve tried both, and unfortunately neither fix the issue. I still get the Socket closed unexpectedly error, which then causes the app to crash (resulting in the 404).

A note: if I change the ping interal to 1000 from 10000 and then save project settings, it opens the updater and resets it. I’ve deployed without it resetting (by not updating) and it still does not work.

Note this code:

const client = createClient(typeof config.redis == 'object' ? config.redis : {
    url: config.redis === true ? 'redis://redis' : config.redis,
    socket: { connectTimeout: 60000 },
    pingInterval: 1000,
});

while i’m not a developer looks related to local/docker redis whereas my issue is with remote redis.

Any other ideas I can try? As soon as I go back to a Docker Redis it works.

i’m using Redis 7 (the only option on DO) and when checking the Redis version in Docker (using the Redis CLI I’m getting redis_version: 7.0.10 so I don’t expect this to be the issue?

And noting, this was actually working well after your last instructions, but since updating - it’s not working again. I’m not sure if it’s related or not.

The only two things that have happened since it waas working:

  • Updating to the latest Wappler (6.1.3)
  • Changing Traefik settings (as I changed the subdomain of staging to staging and prod is now the live version). I don’t believe Traefik has anything to do with it as when I use Docker Redis then both sites work fine (stage and prod).

There seems to be a bug in node-redis when making the connection takes too long.

Patrick was trying to tweak the connection parameters to make it work as stated in the issue.

But in your case I would recommend to just stick to using docker Redis as having Redis on the same server as your project is really the fastest way, without any connection issues.

5 posts were split to a new topic: Scaling Redis horizontally