Skip to content

fix(mssql): socket error handling during connect.#1463

Merged
igalklebanov merged 2 commits intokysely-org:masterfrom
igalklebanov:fix-mssql-socket-error-handling
May 24, 2025
Merged

fix(mssql): socket error handling during connect.#1463
igalklebanov merged 2 commits intokysely-org:masterfrom
igalklebanov:fix-mssql-socket-error-handling

Conversation

@igalklebanov
Copy link
Copy Markdown
Member

@igalklebanov igalklebanov commented May 17, 2025

Hey 👋

closes #1461

Connection establishment errors were not handled correctly leading to infinite loops and undesirable behavior in the MSSQL Dialect. Also, connection disruptions were probably mishandled as well.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 24, 2025 0:57am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2025

kysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1463

commit: 22fa70d

@igalklebanov igalklebanov added bug Something isn't working built-in dialect Related to a built-in dialect mssql Related to MS SQL Server (MSSQL) labels May 17, 2025
@igalklebanov igalklebanov marked this pull request as ready for review May 20, 2025 21:00
@igalklebanov igalklebanov requested review from Copilot and koskimas May 20, 2025 21:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances MSSQL connection handling by properly tracking socket errors, improving promise cleanup, and migrating validation to a private method to avoid infinite reconnect loops.

  • Switches test hook from async to sync where appropriate.
  • Updates Deferred to clear handlers after resolution/rejection.
  • Refactors MssqlConnection to use a deferred connect flow, track ESOCKET errors, and introduce a private validate method.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/node/src/disconnects.test.ts Changed Mocha before hook from async to sync to match the new connection initialization behavior
src/util/deferred.ts Cleans up resolve/reject handlers after they’re invoked to prevent memory leaks
src/dialect/mssql/mssql-driver.ts Adds socket‐error tracking, replaces public validate with a private symbol method, and refines connect/reset/destroy logic
Comments suppressed due to low confidence (1)

src/dialect/mssql/mssql-driver.ts:178

  • Consider adding a test that simulates an 'ESOCKET' error during connection to verify that #hasSocketError is set and subsequent validations correctly fail.
        this.#hasSocketError = true

Comment thread src/dialect/mssql/mssql-driver.ts
Comment thread src/dialect/mssql/mssql-driver.ts
Comment thread src/util/deferred.ts Outdated
@belgattitude
Copy link
Copy Markdown

Thank you for that one ☝️

@igalklebanov igalklebanov merged commit 3f4649c into kysely-org:master May 24, 2025
27 checks passed
@igalklebanov igalklebanov deleted the fix-mssql-socket-error-handling branch May 24, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working built-in dialect Related to a built-in dialect mssql Related to MS SQL Server (MSSQL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSSQL driver reuses one connection despite pool config, causing errors

4 participants