microsoft / microsoft/vscode-mssql

[Bug]: Connection leaks on Object explorer

Open
#21,857 0 comments 0 reactions 1 assignee Claimed by @aasimkhan30 View on GitHub
Area - Connection Area - Object Explorer Bug
Dominant language
TypeScript
Stars
1.9k
Forks
610
Avg merge
2d 3h
Merged PRs (30d)
97

Description

Description

Closing a connection from Object Explorer does not always result in the corresponding SQL sessions being torn down promptly.

Create an OE connection on a new instance of vscode-mssql:

Image

Disconnecting leaves a bunch of stale connections behind:

Image

Going through this a bunch of times can random connections behind:

Image

In Azure Data Studio, this was reported as connections remaining active for up to 30 minutes after the UI connection was closed. The same behavior is worth tracking in vscode-mssql, especially for Azure SQL serverless scenarios where lingering sessions can prevent auto-pause.

Related Azure Data Studio issue:
https://github.com/microsoft/azuredatastudio/issues/25319

Related vscode-mssql issue:
- #19540 (related to pooling/serverless sleep behavior, but not the same manual-close scenario)

Steps to Reproduce

1. Connect to a SQL Server or Azure SQL database in Object Explorer.
2. Optionally expand a database node so that Object Explorer and language-service activity is initialized.
3. In a second session, run the following query to monitor active sessions:

```sql
SELECT
s.session_id,
s.login_name,
s.host_name,
s.program_name,
s.host_process_id,
s.status,
s.login_time,
s.last_request_start_time,
s.last_request_end_time
FROM sys.dm_exec_sessions AS s
WHERE s.is_user_process = 1
AND (
s.program_name LIKE 'vscode-mssql%'
OR s.program_name LIKE 'sqltools%'
)
ORDER BY s.login_time DESC, s.session_id DESC;
```

4. Disconnect the server connection from Object Explorer in VS Code.
5. Re-run the monitoring query shortly after disconnecting.

Expected Behavior

Closing the connection from Object Explorer should promptly close the associated sessions created by vscode-mssql, so that no unnecessary active connections remain.

Actual Behavior

After the connection is closed in the UI, one or more SQL sessions can remain active instead of being terminated promptly.

Affected Area

- Object Explorer
- Connection management
- Potentially language service session cleanup

Environment Information

- VS Code Version:
- MSSQL Extension Version:
- Operating System:
- SQL Server / Azure SQL target:

Additional Notes

- This is particularly noticeable for Azure SQL serverless databases because lingering sessions can prevent auto-pause.
- Connection pooling should be tested both disabled and enabled, since vscode-mssql already has a separate related issue for pooling behavior (#19540).
- If the behavior only reproduces with pooling enabled, this may need to be folded into #19540 instead of tracked separately.

Confirmation

- I have searched existing issues and couldn't find an exact match

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.