Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aborted connection when using ioredis and process.exit(0) #216

Open
brenc opened this issue Oct 4, 2022 · 3 comments
Open

Aborted connection when using ioredis and process.exit(0) #216

brenc opened this issue Oct 4, 2022 · 3 comments

Comments

@brenc
Copy link

brenc commented Oct 4, 2022

I'm not sure if this is a bug with this module or what but I thought I'd start by making note of this very strange issue here for future reference. Using Node v16.17.0 and mariadb v3.0.1 inside a Docker container (node:16-bullseye-slim).

Consider the following ESM:

import Redis from 'ioredis';
import mariadb from 'mariadb';
// import { sleep } from 'modern-async';

const pool = mariadb.createPool({
  connectionLimit: 10,
  database: 'mydb',
  host,
  multipleStatements: true,
  user,
  password,
  trace: true,
});

const redis = new Redis({
  host: process.env.REDIS_HOST,
});

async function main() {
  const queueLen = await redis.llen('queue');
  console.log(`queue length: ${queueLen}`);
}

await main();
await pool.end();
await redis.quit();
// await sleep(100);
process.exit(0);

On exit this causes MariaDB errors like:
[Warning] Aborted connection 632 to db: 'unconnected' user: 'unauthenticated' host: '172.26.0.12' (This connection closed normally without authentication)

It looks like the following conditions have to be met:

  • Create a mariadb pool
  • Use ioredis (perhaps others?) and make a Redis query
  • Exit using process.exit(0)

This set of conditions causes aborted connection errors when the script exits.

Workarounds:

  • Remove process.exit(0). I couldn't do this as I need to signal to Bree (the job runner I use) that the job exited successfully. The aborted connection errors happen whether I'm using Bree or not.
  • Add a short sleep before process.exit(0). Even 100ms seems to prevent these errors from occurring. See the commented out sleep above.
@rusher
Copy link
Collaborator

rusher commented Oct 5, 2022

This is strange, because this kind of error occurs when initiating connection to mariadb server, Server send a 'greeting packet', and connector never sending anything back to server. Server close socket after some time with this type of error.

I would check that there is no firewall between your client and server. (and ensure that assumption with some wireshark logs)

@brenc
Copy link
Author

brenc commented Oct 5, 2022

Yes, very strange. This is all on the internal network. No firewalls. I set up and manage the entire environment so I know for sure.

Like I said, it only happens when those conditions are met. Sometimes the connection does get connected and authenticated and I'll see logs like this as well:

[Warning] Aborted connection 36 to db: 'mydb' user: 'mydb' host: '192.168.0.13' (Got an error reading communication packets)

@MR4online
Copy link

MR4online commented May 2, 2023

we do have a similar setup and similar errors. After moving from mysql2 we have massive problems with pooled connections.


Not sure if following fits here or in #239 or in a new bug report.

I currently think pool.end() does not close all connections, because, when I Query
show status like '%onn%';
I get Results like:
Aborted_connects: 0
Connections: 10

While "Connections" is rising on every service restart with the number of connectionLimit: 10. No closed connections or decreasing connection count, even after minutes.

May be the pool only closes active connections, not idle ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants