Skip to content
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

Refactoring connection management #18684

Merged
merged 22 commits into from
Feb 26, 2025
Merged

Refactoring connection management #18684

merged 22 commits into from
Feb 26, 2025

Conversation

Benjin
Copy link
Contributor

@Benjin Benjin commented Feb 14, 2025

Fixes #18849

  • Lays the groundwork for connection grouping
  • Fixes an issue where similar connections could trample each other in the Object Explorer
  • cleans up a bunch of duplicate or poorly-named code in connection management

Before this change, there was a mix of keys being used, some of which were not guaranteed to be unique. Examples include:

STS-provided session ID (constructed using all properties)
vscode-mssql-generated session ID that seemed like it was supposed to be the same as the STS-provided one, but wasn't always (constructed using four primary connection properties)
OE nodePath

When trying to identify the correct tree node to update, it would store a node label mapping keyed on the server (not guaranteed to be unique among all connections), then later select a saved connection based on the matching server name; if you had multiple connections to the same server, it could end up selecting the wrong one (depending on ordering, IIRC), and expanding the wrong server in the tree (with the right underlying connection, IIRC).

After this change: everything is keyed on the STS sessionID and I'm hoping to remove the concept of a vscode sessionID entirely. It no longer matters how similar a connection is, if any property differs, then it's treated as a separate connection at both layers.

There are still some other cases I need to follow up with (e.g. what gets displayed if there are identical profile names or server + db combos), but this is an important first step.

Before:

416897517-20655331-d79c-4f6f-9010-f4fe4444920a.mp4

After:

connfix.mp4

Copy link

github-actions bot commented Feb 14, 2025

PR Changes

Category Main Branch PR Branch Difference
Code Coverage 50.66% 51.28% $${\color{lightgreen} .62\% }$$
VSIX Size 12982 KB 12983 KB $${\color{lightgreen} 1 KB \space (0\%) }$$
Webview Bundle Size 3188 KB 3188 KB $${\color{lightgreen} 0 KB \space (0\%) }$$

@@ -872,40 +869,30 @@ export class ObjectExplorerService {
isDisconnect: boolean = false,
): Promise<void> {
await this.closeSession(node);
const nodeUri = ObjectExplorerUtils.getNodeUri(node);
const nodeUri = this.getNodeIdentifier(node);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

update ObjectExplorerUtils.getNodeUri()?

@caohai
Copy link
Member

caohai commented Feb 14, 2025

where similar connections could trample each other in the Object Explorer

Do we have an issue for this? Would love to understand how "similar" two connections need to be to trigger this isse, maybe a before/after screenshot with the fix?

(connectionCredentials as IConnectionProfile).profileName,
if ((connectionProfile as IConnectionProfile).profileName) {
this._sessionIdToNodeLabelMap.set(
sessionIdResponse.sessionId,
Copy link
Member

Choose a reason for hiding this comment

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

This part appears to be one of the important changes. At a high level I can see why we want to use sessionId instead of server name but would love to see more detailed explanation of the before/after workfow. (Not necessarily in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, swapping everything to use the sessionId as the sole key was the main change that solidified some unexpected behavior in the OE.

Before this change, there was a mix of keys being used, some of which were not guaranteed to be unique. Examples include:

  • STS-provided session ID (constructed using all properties)
  • vscode-mssql-generated session ID that seemed like it was supposed to be the same as the STS-provided one, but wasn't always (constructed using four primary connection properties)
  • OE nodePath

When trying to identify the correct tree node to update, it would store a node label mapping keyed on the server (not guaranteed to be unique among all connections), then later select a saved connection based on the matching server name; if you had multiple connections to the same server, it could end up selecting the wrong one (depending on ordering, IIRC), and expanding the wrong server in the tree (with the right underlying connection, IIRC).

After this change: everything is keyed on the STS sessionID and I'm hoping to remove the concept of a vscode sessionID entirely. It no longer matters how similar a connection is, if any property differs, then it's treated as a separate connection at both layers.

There are still some other cases I need to follow up with (e.g. what gets displayed if there are identical profile names or server + db combos), but this is an important first step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add recordings of before/after the change

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the detailed explanation!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the detailed explanation.

Can you update the js doc for this interface with some explanation? Something like this maybe

/**
 * A unique session ID used for all requests within a connection sub-tree. 
 * All child nodes must use the same session ID when sending expand requests.
 */

export class CreateSessionResponse {
/**
* Unique Id to use when sending any requests for objects in the tree
* under the node
*/
public sessionId: string;
}

/**
* Unique ID to use when sending any requests for objects in the
* tree under the node
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@caohai before/after recordings now added, with detailed (and consistent) repro information in the bug: #18849

Copy link
Member

@caohai caohai left a comment

Choose a reason for hiding this comment

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

LGTM overall, I'd say we might need do more manual testings next week just to make sure this change won't break any existing OE experience.

@Benjin
Copy link
Contributor Author

Benjin commented Feb 15, 2025

@caohai

I'd say we might need do more manual testings next week just to make sure this change won't break any existing OE experience.

Agreed. I really wanted to get this in on the earlier side of a release cycle, but too many things were competing with my time when I wanted to get this PR out. The right call could be to hold this PR after the release branch splits so we can decide whether to take it as a port.

Copy link
Contributor

@aasimkhan30 aasimkhan30 left a comment

Choose a reason for hiding this comment

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

Thanks for the code cleanup. Left a comment about a jsdoc comment.

@Benjin Benjin merged commit 5e1d743 into main Feb 26, 2025
6 checks passed
@Benjin Benjin deleted the dev/benjin/connRefac branch February 26, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Object Explorer broken when working with connections that differ only by secondary settings
4 participants