microsoft / azuredatastudio

Azure Data Studio is a data management and development tool with connectivity to popular cloud and on-premises databases. Azure Data Studio supports Windows, macOS, and Linux, with immediate capability to connect to Azure SQL and SQL Server. Browse the extension library for more database support options including MySQL, PostgreSQL, and MongoDB.
https://learn.microsoft.com/sql/azure-data-studio
MIT License
7.58k stars 908 forks source link

Not able to expand node for Azure SQL Database connection #22092

Open cheenamalhotra opened 1 year ago

cheenamalhotra commented 1 year ago

Steps to Reproduce:

  1. Connect to Azure SQL Database (non-master)
  2. Expand OE connection

Noticed this error log today:

Expanding cmalhotra2.database.windows.net
23-03-01 18:12:08.0612610 pid:46536 tid:20 sqltools Verbose: 0 : Populating oe node :cmalhotra2.database.windows.net
23-03-01 18:12:08.0613299 pid:46536 tid:20 sqltools Verbose: 0 : Begin populate children for cmalhotra2.database.windows.net using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.ServerChildFactory factory
23-03-01 18:12:08.0614026 pid:46536 tid:20 sqltools Verbose: 0 : child factory parent :cmalhotra2.database.windows.net
23-03-01 18:12:08.0614154 pid:46536 tid:12 sqltools Verbose: 0 : Sending message of id[], of type[Event] and method[objectexplorer/expandCompleted]
23-03-01 18:12:08.0614666 pid:46536 tid:20 sqltools Verbose: 0 : End populate children for cmalhotra2.database.windows.net using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.ServerChildFactory factory
23-03-01 18:12:08.0616209 pid:46536 tid:17 sqltools Verbose: 0 : Done with binding operation for cmalhotra2.database.windows.net
23-03-01 18:12:08.0622290 pid:46536 tid:12 sqltools Verbose: 0 : Sending message of id[], of type[Event] and method[objectexplorer/expandCompleted]
23-03-01 18:12:08.0951532 pid:46536 tid:14 sqltools Verbose: 0 : eventTID:21536 <sc.SqlConfigurableRetryLogicLoader.MakeFullPath|INFO> Looking for 'Microsoft.SqlTools.Hosting.resources' assembly in 'E:\azuredatastudio\.build\electron' directory.
23-03-01 18:12:08.0952226 pid:46536 tid:14 sqltools Verbose: 0 : eventTID:21536 <sc.SqlConfigurableRetryLogicLoader.MakeFullPath|INFO> Looking for 'Microsoft.SqlTools.Hosting.resources' assembly by 'E:\azuredatastudio\.build\electron\Microsoft.SqlTools.Hosting.resources' full path.
23-03-01 18:12:08.0953008 pid:46536 tid:14 sqltools Verbose: 0 : eventTID:21536 <sc.SqlConfigurableRetryLogicLoader.Default_Resolving|INFO> Looking for 'Microsoft.SqlTools.Hosting.resources, Version=1.0.0.0, Culture=en, PublicKeyToken=null' assembly that is requested by '"Default" System.Runtime.Loader.DefaultAssemblyLoadContext #1' ALC from 'null' path.
23-03-01 18:12:08.1573417 pid:46536 tid:14 sqltools Error: 0 : Failed expanding oe children. parent:cmalhotra2.database.windows.net/sql-basic-dtu5-new error:Cannot register service for type SmoQuerier, one or more services already registered inner: stacktrace:   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.ThrowIfAlreadyRegistered(Type type) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 86
   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.ThrowIfAlreadyRegistered[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 79
   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.Register[T](Func`1 serviceLookup) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 72
   at Microsoft.SqlTools.Extensibility.ExtensionServiceProvider.EnsureExtensionStoreRegistered[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\ExtensionServiceProvider.cs:line 115
   at Microsoft.SqlTools.Extensibility.ExtensionServiceProvider.GetServicesImpl[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\ExtensionServiceProvider.cs:line 106
   at Microsoft.SqlTools.Extensibility.ServiceProviderBase.GetServices[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\IMultiServiceProvider.cs:line 73
   at Microsoft.SqlTools.Extensibility.ServiceProviderBase.GetServices[T](Predicate`1 filter) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\IMultiServiceProvider.cs:line 68
   at Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoChildFactoryBase.OnExpandPopulateNonFolders(IList`1 allChildren, TreeNode parent, Boolean refresh, String name, CancellationToken cancellationToken) in E:\sts\src\Microsoft.SqlTools.ServiceLayer\ObjectExplorer\SmoModel\SmoChildFactoryBase.cs:line 131
   at Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoChildFactoryBase.Expand(TreeNode parent, Boolean refresh, String name, Boolean includeSystemObjects, CancellationToken cancellationToken) in E:\sts\src\Microsoft.SqlTools.ServiceLayer\ObjectExplorer\SmoModel\SmoChildFactoryBase.cs:line 36
23-03-01 18:12:08.1577461 pid:46536 tid:14 sqltools Error: 0 : Failed populating oe children. error:Cannot register service for type SmoQuerier, one or more services already registered inner: stacktrace:   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.ThrowIfAlreadyRegistered(Type type) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 86
   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.ThrowIfAlreadyRegistered[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 79
   at Microsoft.SqlTools.Extensibility.RegisteredServiceProvider.Register[T](Func`1 serviceLookup) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\RegisteredServiceProvider.cs:line 72
   at Microsoft.SqlTools.Extensibility.ExtensionServiceProvider.EnsureExtensionStoreRegistered[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\ExtensionServiceProvider.cs:line 115
   at Microsoft.SqlTools.Extensibility.ExtensionServiceProvider.GetServicesImpl[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\ExtensionServiceProvider.cs:line 106
   at Microsoft.SqlTools.Extensibility.ServiceProviderBase.GetServices[T]() in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\IMultiServiceProvider.cs:line 73
   at Microsoft.SqlTools.Extensibility.ServiceProviderBase.GetServices[T](Predicate`1 filter) in E:\sts\src\Microsoft.SqlTools.Hosting\Extensibility\IMultiServiceProvider.cs:line 68
   at Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoChildFactoryBase.OnExpandPopulateNonFolders(IList`1 allChildren, TreeNode parent, Boolean refresh, String name, CancellationToken cancellationToken) in E:\sts\src\Microsoft.SqlTools.ServiceLayer\ObjectExplorer\SmoModel\SmoChildFactoryBase.cs:line 131
   at Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoChildFactoryBase.Expand(TreeNode parent, Boolean refresh, String name, Boolean includeSystemObjects, CancellationToken cancellationToken) in E:\sts\src\Microsoft.SqlTools.ServiceLayer\ObjectExplorer\SmoModel\SmoChildFactoryBase.cs:line 36
   at Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes.TreeNode.PopulateChildren(Boolean refresh, String name, CancellationToken cancellationToken, String accessToken) in E:\sts\src\Microsoft.SqlTools.ServiceLayer\ObjectExplorer\Nodes\TreeNode.cs:line 355
23-03-01 18:12:08.1591202 pid:46536 tid:18 sqltools Verbose: 0 : Done with binding operation for cmalhotra2.database.windows.net/sql-basic-dtu5-new
23-03-01 18:12:08.1592856 pid:46536 tid:12 sqltools Verbose: 0 : Sending message of id[], of type[Event] and method[objectexplorer/expandCompleted]
cheenamalhotra commented 1 year ago

Looks like a concurrency issue. Would recommend changing services dictionary to ConcurrentDictionary:

protected Dictionary<Type, ServiceLookup> services = new Dictionary<Type, ServiceLookup>(); Link to source

cheenamalhotra commented 1 year ago

Raising priority since it's happening consistently for me.

cheenamalhotra commented 1 year ago

I think this may be happening due to Parallel Message processing being enabled by default. https://github.com/microsoft/azuredatastudio/blob/711923cd4611c7be13027177b351a806657bd1e0/extensions/mssql/src/utils.ts#L132

@alanrenmsft was it intended to be true by default?

alanrenmsft commented 1 year ago

@cheenamalhotra it is intentional to enable it by default for dev build to catch issues. I think you can remove the p0 flag and I can work with you to debug the issue.