Skip to content

Conversation

@isaru66
Copy link
Contributor

@isaru66 isaru66 commented Mar 28, 2024

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

re-run circleci test?

Copy link
Collaborator

@gioboa gioboa left a comment

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 Simple tasks that require minimal effort. Estimated effort: 1-2 hours. label Jan 24, 2025
@veyselkaraca
Copy link

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 ?

Copy link
Collaborator

@gioboa gioboa left a comment

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

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

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
Copy link
Collaborator

@sgarner sgarner left a comment

Choose a reason for hiding this comment

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

Thanks @isaru66 💜

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

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
Copy link

pkg-pr-new bot commented Sep 24, 2025

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

Coverage Status

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

@sgarner sgarner merged commit 83e3a8a into typeorm:master Sep 24, 2025
115 of 122 checks passed
@github-project-automation github-project-automation bot moved this from Proposed to Done in TypeORM Roadmap Sep 24, 2025
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-s Simple tasks that require minimal effort. Estimated effort: 1-2 hours.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants