kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.82k stars 275 forks source link

Error connecting to MSSQL database with clustering enabled #1200

Open nick-w-nick opened 3 weeks ago

nick-w-nick commented 3 weeks ago

After connecting to a MSSQL database that has clustering/availability zones enabled, I am getting this error message after making a query:

UnexpectedTokenError: Unexpected token `ENVCHANGE` in `RequestTokenHandler`
    at RequestTokenHandler.onDatabaseMirroringPartner (/Users/user/Documents/GitHub/service-name/node_modules/tedious/src/token/handler.ts:140:11)

This error is not present in our other identical MSSQL databases where clustering is disabled.

I realize this seems to be an error stemming from tedious, but I thought this repo would be more suitable to ask for help, as we are also using tedious with Sequelize and have no issues connecting to the exact same database.

We have also verified that we don't seem to have database mirroring enabled, but are somehow still getting sent a DatabaseMirroringPartner event, which is causing the unhandled exception to be thrown.

Any help or insight would be much appreciated.

Thank you!

igalklebanov commented 3 weeks ago

Hey 👋

I think asking this in the tedious repository is best. These are some undocumented internals I have no clue about.

It seems unrelated to kysely and MssqlDialect, but historically, we already had some issues with tedious that were caused by MssqlDialect not handling some undocumented tedious event. Leaving this open for visibility.

nick-w-nick commented 2 weeks ago

@igalklebanov From my research, it seems like the tarn resource pool may be causing the DatabaseMirroringPartner events to be sent due to how it handles the resource pool, since Sequelize uses a custom resource pool and does not have this issue. It may be worth looking into making the tarn property of the MssqlDialect class accept a generic resource pool that implements the tarn methods rather than forcing the usage of tarn.

Regardless, I have a PR open in the tedious repo to fix this issue, FYI. If that gets merged, it should solve the incompatibility issue at the root rather than requiring changes to how pooling works.