Skip to content

[Bug]: Connection leaks on Object explorer #21857

@aasimkhan30

Description

@aasimkhan30

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:
microsoft/azuredatastudio#25319

Related vscode-mssql issue:

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:
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;
  1. Disconnect the server connection from Object Explorer in VS Code.
  2. 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

Confirmation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions