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

"Invalid argument" exception expanding OE database node #2914

Open
kburtram opened this Issue Oct 16, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@kburtram
Member

kburtram commented Oct 16, 2018

An Invalid Argument error is sometime hit when trying to expand an OE node. This is happening somewhat frequently when connecting to SQL 2019 servers from macOS laptops after leaving a connection inactive for several minutes.

The error message is coming from .Net Core Sockets library via SQL Tools Service->SMO->SqlClient. I'll investigate how best to recover from this error higher up in the application stack.

screen shot 2018-10-16 at 3 11 28 pm

"System.Net.Sockets.SocketException (22): Invalid argument\n   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)"
System.Net.Sockets.dll!System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(System.Net.Sockets.SocketError error, string callerName) (Unknown Source:0)
System.Net.Sockets.dll!System.Net.Sockets.Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionValue, bool silent) (Unknown Source:0)
System.Net.Sockets.dll!System.Net.Sockets.Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionValue) (Unknown Source:0)
System.Net.Sockets.dll!System.Net.Sockets.Socket.ReceiveTimeout.set(int value) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SNI.SNITCPHandle.Receive(out System.Data.SqlClient.SNI.SNIPacket packet, int timeoutInMilliseconds) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SNI.TdsParserStateObjectManaged.ReadSyncOverAsync(int timeoutRemaining, out uint error) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParserStateObject.TryReadByte(out byte value) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParser.TryRun(System.Data.SqlClient.RunBehavior runBehavior, System.Data.SqlClient.SqlCommand cmdHandler, System.Data.SqlClient.SqlDataReader dataStream, System.Data.SqlClient.BulkCopySimpleResultSet bulkCopyHandler, System.Data.SqlClient.TdsParserStateObject stateObj, out bool dataReady) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParser.Run(System.Data.SqlClient.RunBehavior runBehavior, System.Data.SqlClient.SqlCommand cmdHandler, System.Data.SqlClient.SqlDataReader dataStream, System.Data.SqlClient.BulkCopySimpleResultSet bulkCopyHandler, System.Data.SqlClient.TdsParserStateObject stateObj) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.TdsParser.DrainData(System.Data.SqlClient.TdsParserStateObject stateObj) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(System.Data.SqlClient.SqlCommand command) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SqlCommand.ValidateCommand(bool async, string method) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior cmdBehavior, System.Data.SqlClient.RunBehavior runBehavior, bool returnStream, System.Threading.Tasks.TaskCompletionSource<object> completion, int timeout, out System.Threading.Tasks.Task task, bool asyncWrite, string method) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SqlCommand.ExecuteReader(System.Data.CommandBehavior behavior) (Unknown Source:0)
System.Data.SqlClient.dll!System.Data.SqlClient.SqlCommand.ExecuteReader() (Unknown Source:0)
Microsoft.SqlServer.ConnectionInfo.dll!Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSqlAction action, object execObject, System.Data.DataSet fillDataSet, bool catchException) (Unknown Source:0)
Microsoft.SqlServer.ConnectionInfo.dll!Microsoft.SqlServer.Management.Common.ServerConnection.GetExecuteReader(System.Data.SqlClient.SqlCommand command) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataReader(string query, out System.Data.SqlClient.SqlCommand command) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.DataProvider.SetConnectionAndQuery(Microsoft.SqlServer.Management.Smo.ExecuteSql execSql, string query) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataProvider(System.Collections.Specialized.StringCollection query, object con, Microsoft.SqlServer.Management.Smo.StatementBuilder sb, Microsoft.SqlServer.Management.Smo.DataProvider.RetriveMode rm) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillData(Microsoft.SqlServer.Management.Sdk.Sfc.ResultType resultType, System.Collections.Specialized.StringCollection sql, object connectionInfo, Microsoft.SqlServer.Management.Smo.StatementBuilder sb) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillDataWithUseFailure(Microsoft.SqlServer.Management.Smo.SqlEnumResult sqlresult, Microsoft.SqlServer.Management.Sdk.Sfc.ResultType resultType) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.SqlObjectBase.BuildResult(Microsoft.SqlServer.Management.Sdk.Sfc.EnumResult result) (Unknown Source:0)
Microsoft.SqlServer.SqlEnum.dll!Microsoft.SqlServer.Management.Smo.DatabaseLevel.GetData(Microsoft.SqlServer.Management.Sdk.Sfc.EnumResult res) (Unknown Source:0)
Microsoft.SqlServer.Management.Sdk.Sfc.dll!Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData() (Unknown Source:0)
Microsoft.SqlServer.Management.Sdk.Sfc.dll!Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData(Microsoft.SqlServer.Management.Sdk.Sfc.Request req, object ci) (Unknown Source:0)
Microsoft.SqlServer.Management.Sdk.Sfc.dll!Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(object connectionInfo, Microsoft.SqlServer.Management.Sdk.Sfc.Request request) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.ExecutionManager.GetEnumeratorDataReader(Microsoft.SqlServer.Management.Sdk.Sfc.Request req) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetInitDataReader(string[] fields, Microsoft.SqlServer.Management.Sdk.Sfc.OrderBy[] orderby) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.SqlSmoObject.ImplInitialize(string[] fields, Microsoft.SqlServer.Management.Sdk.Sfc.OrderBy[] orderby) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.SqlSmoObject.OnPropertyMissing(string propname, bool useDefaultValue) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.PropertyCollection.RetrieveProperty(int index, bool useDefaultOnMissingValue) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.Database.CompatibilityLevel.get() (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.Database.CheckDbCompatibilityLevel() (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.SqlSmoObject.Initialize(bool allProperties) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.SqlSmoObject.OnPropertyMissing(string propname, bool useDefaultValue) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.PropertyCollection.RetrieveProperty(int index, bool useDefaultOnMissingValue) (Unknown Source:0)
Microsoft.SqlServer.Smo.dll!Microsoft.SqlServer.Management.Smo.Database.IsAccessible.get() (Unknown Source:0)
MicrosoftSqlToolsServiceLayer.dll!Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.DatabaseTreeNode.IsAccessible(Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoQueryContext context) Line 69 (/xplat/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/DatabaseTreeNode.cs:69)
MicrosoftSqlToolsServiceLayer.dll!Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.DatabaseTreeNode.PopulateChildren(bool refresh, string name, System.Threading.CancellationToken cancellationToken) Line 47 (/xplat/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/DatabaseTreeNode.cs:47)
MicrosoftSqlToolsServiceLayer.dll!Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes.TreeNode.Refresh(System.Threading.CancellationToken cancellationToken) Line 267 (/xplat/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/TreeNode.cs:267)
MicrosoftSqlToolsServiceLayer.dll!Microsoft.SqlTools.ServiceLayer.ObjectExplorer.ObjectExplorerService.QueueExpandNodeRequest.AnonymousMethod__0(Microsoft.SqlTools.ServiceLayer.LanguageServices.IBindingContext bindingContext, System.Threading.CancellationToken cancelToken) Line 421 (/xplat/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs:421)
MicrosoftSqlToolsServiceLayer.dll!Microsoft.SqlTools.ServiceLayer.LanguageServices.BindingQueue<Microsoft.SqlTools.ServiceLayer.LanguageServices.ConnectedBindingContext>.ProcessQueue.AnonymousMethod__1() Line 345 (/xplat/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs:345)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() (Unknown Source:0)
[Native to Managed Transition] (Unknown Source:0)

@kburtram kburtram added this to the November Release milestone Oct 16, 2018

@kburtram kburtram self-assigned this Oct 16, 2018

@MattIrv

This comment has been minimized.

Member

MattIrv commented Oct 16, 2018

I have a fairly consistent repro for this:

  1. Connect to a server
  2. Disconnect from the VPN / from wifi
  3. Try to expand something that wasn't already expanded or refresh something

The expansion will eventually time out with "Invalid argument"

Not sure how this would be happening during normal use though unless the VPN connection is going in and out

@kburtram

This comment has been minimized.

Member

kburtram commented Oct 19, 2018

The underlying socket issue is that on non-Windows platforms the connection doesn't set the KeepAlive option. This causes the socket to get into a closed state in some situation after periods of inactivity.

This PR enables KeepAlive on SqlClient sockets, but since it is a change to .Net Core we'll need to figure out how best to consume this fix kburtram/corefx#1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment