-
Notifications
You must be signed in to change notification settings - Fork 321
Fix enhanced routing ack handling #3922
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
base: feat/enhanced-routing
Are you sure you want to change the base?
Fix enhanced routing ack handling #3922
Conversation
There was a problem hiding this 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 improves handling of enhanced routing support in the SQL client by ensuring that enhanced routing information is only used when the server acknowledges support for the feature. The changes include updates to both netcore and netfx implementations, refactored unit tests, and enhanced simulated server logic.
Changes:
- Added validation in SqlInternalConnectionTds to ignore enhanced routing info when the server has not acknowledged the feature
- Updated OnFeatureExtAck to process enhanced routing support acknowledgments even when RoutingInfo is present
- Refactored ConnectionEnhancedRoutingTests to use a helper class and Theory-based tests for better maintainability
- Enhanced RoutingTdsServer to send feature extension acknowledgment tokens for enhanced routing
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs | Added checks to ignore enhanced routing info without feature ack; updated OnFeatureExtAck to handle enhanced routing support |
| src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs | Same changes as netcore for consistency across platforms |
| src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionEnhancedRoutingTests.cs | Refactored tests using TestRoutingServers helper class and Theory attributes for sync/async testing |
| src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/RoutingTdsServer.cs | Added logic to send enhanced routing feature acknowledgment token (contains a critical bug) |
|
|
||
| // Create the option data | ||
| byte[] data = EnhancedRoutingBehavior == FeatureExtensionBehavior.Enabled ? [1] : [0]; | ||
| TDSFeatureExtAckGenericOption enhancedRoutingSupportOption = new TDSFeatureExtAckGenericOption(TDSFeatureID.EnhancedRoutingSupport, (uint)data.Length, data); | ||
|
|
||
| TDSFeatureExtAckToken featureExtAckToken = new TDSFeatureExtAckToken(enhancedRoutingSupportOption); | ||
| // Add it before DONE token if possible, but simplest is to add to end and let the sorting logic handle it or just append | ||
| // Ideally, find DONE token and insert before it | ||
| int doneIndex = targetMessage.FindIndex(t => t is TDSDoneToken); | ||
| if (doneIndex >= 0) | ||
| { | ||
| targetMessage.Insert(doneIndex, featureExtAckToken); | ||
| } | ||
| else | ||
| { | ||
| targetMessage.Add(featureExtAckToken); |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enhanced routing feature acknowledgment token is being added twice - once by the base class GenericTdsServer.OnAuthenticationCompleted (lines 692-717 in GenericTdsServer.cs) and again by this override in RoutingTdsServer. This creates a duplicate TDSFeatureExtAckToken in the response message.
The code should follow the same pattern as the base class: check if a TDSFeatureExtAckToken already exists in targetMessage, and if so, add the option to it instead of creating a new token. Alternatively, since the base class already handles this feature acknowledgment, this code in the override may not be necessary at all.
| // Create the option data | |
| byte[] data = EnhancedRoutingBehavior == FeatureExtensionBehavior.Enabled ? [1] : [0]; | |
| TDSFeatureExtAckGenericOption enhancedRoutingSupportOption = new TDSFeatureExtAckGenericOption(TDSFeatureID.EnhancedRoutingSupport, (uint)data.Length, data); | |
| TDSFeatureExtAckToken featureExtAckToken = new TDSFeatureExtAckToken(enhancedRoutingSupportOption); | |
| // Add it before DONE token if possible, but simplest is to add to end and let the sorting logic handle it or just append | |
| // Ideally, find DONE token and insert before it | |
| int doneIndex = targetMessage.FindIndex(t => t is TDSDoneToken); | |
| if (doneIndex >= 0) | |
| { | |
| targetMessage.Insert(doneIndex, featureExtAckToken); | |
| } | |
| else | |
| { | |
| targetMessage.Add(featureExtAckToken); | |
| // Create the option data | |
| byte[] data = EnhancedRoutingBehavior == FeatureExtensionBehavior.Enabled ? [1] : [0]; | |
| TDSFeatureExtAckGenericOption enhancedRoutingSupportOption = new TDSFeatureExtAckGenericOption(TDSFeatureID.EnhancedRoutingSupport, (uint)data.Length, data); | |
| // Follow the base class pattern: reuse an existing FeatureExtAck token if present | |
| TDSFeatureExtAckToken featureExtAckToken = targetMessage.OfType<TDSFeatureExtAckToken>().FirstOrDefault(); | |
| if (featureExtAckToken != null) | |
| { | |
| // Add the enhanced routing option to the existing FeatureExtAck token | |
| featureExtAckToken.Options.Add(enhancedRoutingSupportOption); | |
| } | |
| else | |
| { | |
| // No existing FeatureExtAck token; create and insert a new one | |
| featureExtAckToken = new TDSFeatureExtAckToken(enhancedRoutingSupportOption); | |
| // Add it before DONE token if possible; otherwise append to the end | |
| int doneIndex = targetMessage.FindIndex(t => t is TDSDoneToken); | |
| if (doneIndex >= 0) | |
| { | |
| targetMessage.Insert(doneIndex, featureExtAckToken); | |
| } | |
| else | |
| { | |
| targetMessage.Add(featureExtAckToken); | |
| } |
This pull request improves the handling of enhanced routing support in the SQL client and updates the associated unit tests and server simulation logic. The main focus is ensuring that enhanced routing information is only used when the server acknowledges support for the feature, and making the tests more robust and maintainable.
Enhanced Routing Feature Handling:
SqlInternalConnectionTds.csto ignore enhanced routing info if the server has not acknowledged support for the feature, preventing unintended routing. [1] [2] [3] [4]OnFeatureExtAckmethod to properly handle the new enhanced routing feature acknowledgment alongside existing feature checks. [1] [2]Unit Test Improvements:
ConnectionEnhancedRoutingTests.csto use a newTestRoutingServershelper class, simplifying test setup and teardown, reducing code duplication, and covering both sync and async connection scenarios with[Theory].Simulated Server Logic:
RoutingTdsServerto send the appropriate feature extension acknowledgment token for enhanced routing, depending on the configured behavior, making tests more accurate and reflective of real server behavior.