Skip to content

fix: add multiSubnetFailover to mssql driver option types - #10804

Merged
sgarner merged 1 commit into
typeorm:masterfrom
isaru66:master
Sep 24, 2025
Merged

sgarner merged 1 commit into
typeorm:masterfrom
isaru66:master

Conversation

@isaru66

@isaru66 isaru66 commented Mar 28, 2024 •

Copy link
Copy Markdown
Contributor

Description of change

add multiSubnetFailover option for SqlServerConnectionOptions.

This will support MSSQL alway on avalibility group to be failover faster
image
ref: https://learn.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/sql-server-multi-subnet-clustering-sql-server?view=sql-server-ver16#DNS

in tediousjs this feature was implemented in tediousjs/tedious#362

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Summary by CodeRabbit

  • New Features
    • Added a multiSubnetFailover option for the SQL Server data source. When enabled, the driver attempts connections to all DNS-resolved IPs in parallel to improve failover in multi-subnet environments. Disabled by default.
  • Documentation
    • Updated SQL Server configuration docs to include the multiSubnetFailover option, its behavior, default value, and usage guidance.

@rjminchuk

Copy link
Copy Markdown

re-run circleci test?

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @isaru66
I added this PR to our release board

@gioboa gioboa added the size-s label Jan 24, 2025
@veyselkaraca

Copy link
Copy Markdown

Hi,

This PR would be very useful for those of us working with SQL Server in high availability setups.
In our production environment we also rely on HA databases, and the MultiSubnetFailover option is important to keep connections stable during failovers.

Since many large-scale applications use this type of database configuration, having support for this parameter in TypeORM would be a solid improvement.

Is there anything blocking this from being merged ?

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see, there are conflicts and we need another reviewer, then we can merge it 👍

@veyselkaraca

Copy link
Copy Markdown

Thanks a lot for the review and clarification 👍
Since the change is quite small (just passing the parameter and updating the docs), would it make sense to resolve the conflicts and tag another maintainer for review? That way we could hopefully get this merged soon.

@veyselkaraca

Copy link
Copy Markdown

Hi @sgarner , @michaelbromley,

This PR has been open since March 2024 and already has one approval.
The change is quite small (adding support for the MultiSubnetFailover parameter in SQL Server connections, plus a docs update), but it’s important for working with HA databases.

Would you mind taking a quick look so we can hopefully get this merged ?

@gioboa
gioboa requested review from alumni and naorpeled September 23, 2025 10:49

@sgarner sgarner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @isaru66 💜

@coderabbitai

coderabbitai Bot commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new optional Sql Server connection option multiSubnetFailover?: boolean to the TypeScript interface and documents it in the SQL Server driver docs. No control flow or runtime logic changes are included in this diff.

Changes

Cohort / File(s) Summary
Documentation: SQL Server driver options
docs/docs/drivers/microsoft-sqlserver.md
Documents a new boolean data source option multiSubnetFailover (default false) that, when enabled, indicates parallel connection attempts to all DNS-resolved IPs.
Type definitions: SQL Server connection options
src/driver/sqlserver/SqlServerConnectionOptions.ts
Adds multiSubnetFailover?: boolean to SqlServerConnectionOptions with comment explaining its purpose. No other signatures changed.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor App as Application
    participant Driver as SQL Server Driver
    participant DNS as DNS
    participant IPs as Target IPs

    App->>Driver: createConnection({ multiSubnetFailover })
    Driver->>DNS: Resolve hostname -> IP list
    DNS-->>Driver: [IP1, IP2, ...]
    
    alt multiSubnetFailover = false
        note right of Driver: Default behavior
        Driver->>IPs: Attempt connect to first IP, fallback sequentially
        IPs-->>Driver: First successful connection
    else multiSubnetFailover = true
        rect rgba(200, 230, 255, 0.3)
        note right of Driver: Parallel connection attempts
        Driver->>IPs: Connect to all resolved IPs in parallel
        IPs-->>Driver: First successful connection wins
        end
        Driver--x IPs: Cancel remaining attempts
    end

    Driver-->>App: Connected SqlServer client
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A hop, a skip, across subnets I go,
Parallel burrows where IP rivers flow.
Flip one flag—I’m swift as spring clover,
First tunnel wins, the search is over.
Thump-thump! says the driver, eager and able—
Multi-subnet dreams on my connection table. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and succinctly summarizes the primary change by stating that the multiSubnetFailover option is being added to the MSSQL driver’s option types, directly reflecting the core intent of the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4f7b44 and 2e0ab1a.

📒 Files selected for processing (2)
  • docs/docs/drivers/microsoft-sqlserver.md (1 hunks)
  • src/driver/sqlserver/SqlServerConnectionOptions.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: tests-linux (20) / mssql
  • GitHub Check: tests-linux (18) / postgres (17)
  • GitHub Check: tests-linux (18) / mssql
  • GitHub Check: tests-windows / sqljs
  • GitHub Check: tests-windows / better-sqlite3
🔇 Additional comments (2)
src/driver/sqlserver/SqlServerConnectionOptions.ts (1)

294-298: Option wiring LGTM

The new multiSubnetFailover flag fits naturally alongside the existing options.* passthrough and keeps the contract aligned with Tedious, so consumers can finally opt into parallel DNS connect attempts.

docs/docs/drivers/microsoft-sqlserver.md (1)

152-153: Docs addition looks great

Thanks for documenting the new option right away—makes it easy for folks deploying against Always On setups to discover.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2025

Copy link
Copy Markdown

typeorm-sql-js-example

npm i https://pkg.pr.new/typeorm/typeorm@10804

commit: 2e0ab1a

@sgarner sgarner changed the title fix: add multiSubnetFailover option for mssql fix: add multiSubnetFailover to mssql driver option types Sep 24, 2025
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 76.427%. remained the same
when pulling 2e0ab1a on isaru66:master
into d4f7b44 on typeorm:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants