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

Multiple ConnectionError with MSSQL #1283

Open
y-wertz-priomold opened this issue Nov 28, 2024 · 0 comments
Open

Multiple ConnectionError with MSSQL #1283

y-wertz-priomold opened this issue Nov 28, 2024 · 0 comments

Comments

@y-wertz-priomold
Copy link

I'm currently testing stability of my node app with kysely and getting strange behaviour when connection to my mssql database has errors.

For example when I cange my database user or password (to wrong credentials) I'm getting hundreds of connection errors:

ConnectionError: Fehler bei der Anmeldung für den Benutzer "prio".
    at Login7TokenHandler.onErrorMessage (C:\Yannik\ENTWICKLUNG\pips-2024\pips-backend\node_modules\tedious\src\token\handler.ts:266:19)
    at Readable.<anonymous> (C:\Yannik\ENTWICKLUNG\pips-2024\pips-backend\node_modules\tedious\src\token\token-stream-parser.ts:23:55)
    at Readable.emit (node:events:514:28)
    at Readable.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushObjectMode (node:internal/streams/readable:521:3)
    at Readable.push (node:internal/streams/readable:376:5)
    at next (node:internal/streams/from:98:31)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ELOGIN'
}

Similar behaviour when I screw up my IP adress (from 192.168.21.146 to 192.168.21.1466 (I know this is bs and invalid))

ConnectionError: Failed to connect to 192.168.21.1466:1433 - getaddrinfo ENOTFOUND 192.168.21.1466
    at Connection.socketError (C:\Yannik\ENTWICKLUNG\pips-2024\pips-backend\node_modules\tedious\src\connection.ts:2334:28)
    at C:\Yannik\ENTWICKLUNG\pips-2024\pips-backend\node_modules\tedious\src\connection.ts:2123:37
    at processTicksAndRejections (node:internal/process/task_queues:77:11) {
  code: 'ESOCKET',
  [cause]: Error: getaddrinfo ENOTFOUND 192.168.21.1466
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: '192.168.21.1466'
  }
}

Both errors are just printed, not thrown.

This second case is unlikly (up to impossible) in production. But the first case (database user login credentials change) is possible.

It doesn't crash the app completly, but because this error repeats very often (for a single query) is freezes the application..

My config looks like following:

const dialect = new MssqlDialect({
  tarn: {
    ...tarn,
    options: {
      min: 0,
      max: 10,
    },
  },
  tedious: {
    ...tedious,
    connectionFactory: () =>
      new tedious.Connection({
        authentication: {
          options: {
            password: config.SOU_PASSWORD,
            userName: config.SOU_USER,
          },
          type: "default",
        },
        options: {
          database: config.SOU_DATABASE,
          port: 1433,
          trustServerCertificate: true,
          maxRetriesOnTransientErrors: 0,
          connectTimeout: 1000,
          requestTimeout: 1000,
        },
        server: config.SOU_HOST,
      }),
  },
});

export const db = new Kysely<DB>({
  dialect: dialect,
});

And my query look like following:

const sqlResultAuftragseingang = await db
    .selectFrom("AuftragPos")
    // is reality here is a working query
    .executeTakeFirst()
    .catch((err) => err as Error);

  // Guard further execution
  if (isError(sqlResultAuftragseingang)) {
    // log error to console and send to client
    sendError(sqlResultAuftragseingang)
  }

Even if the Timeout is set to a short amount of time and retries is set to zero, it seems to retry very often until the Promise from Kyselys execute() Function resolves with an error.

Expected behaviour

After timeout or on connection error the execute() promise resolves instantly with an error, without blocking a long time before resolving the promise.

Am I doing something wrong in my config or is this a bug?

Thanks!

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

1 participant