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

Unhandled exception at FirebirdSql.Data.Client.Managed.FirebirdNetworkStream.Flush() [DNET1014] #927

Closed
firebird-automations opened this issue Feb 3, 2021 · 17 comments

Comments

@firebird-automations
Copy link

Submitted by: @luronumen

ACTUAL RESULT:
Under certain conditions where network failures can happen more frequently (high latency network), the following unhandled exception can happen:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
FirebirdSql.Data.Common.IscException: Unable to complete network request to host "
No message for error code 335544721 found. ---> System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at FirebirdSql.Data.Client.Managed.FirebirdNetworkStream.Flush()
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.DoFreePacket(Int32 option)
--- End of inner exception stack trace ---
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.DoFreePacket(Int32 option)
at FirebirdSql.Data.Client.Managed.Version11.GdsStatement.Free(Int32 option)
at FirebirdSql.Data.Common.StatementBase.Release()
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.Dispose()
at FirebirdSql.Data.FirebirdClient.FbCommand.Release()
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at CHRONOS.Models.Databases.FirebirdSQLDatabase.SelectProcedure(String procedureName, String[] inputParameters, DataTable dataTable, Boolean poolingStatus)

EXPECTED RESULT
This unhandled exception should be redirected to the FbException class.

OHTER INFORMATION
Here is the code of the procedure that the unhandled exception happens:
private static bool SelectProcedure(string procedureName, string[] inputParameters, out DataTable dataTable, bool poolingStatus = true)
{
dataTable = new DataTable();
using (var fbConnection = new FbConnection(ConnectionString()))
using (var fbCommand = new FbCommand(procedureName, fbConnection))
try
{
Cursor.Current = Cursors.WaitCursor;
fbCommand.CommandType = CommandType.StoredProcedure;
//INPUT PARAMETERS
for (var i = 0; i < inputParameters.Length; i++)
fbCommand.Parameters.Add("@" + i, inputParameters[i]).Direction = ParameterDirection.Input;
//OPEN CONNECTION
fbConnection.Open();
//SELECT PROCEDURE
using (var fbDataReader = fbCommand.ExecuteReader())
dataTable.Load(fbDataReader);
NotifyReconnection();
Utility.Log("SP", procedureName);
return true;
}
catch (FbException ex)
{
if (poolingStatus)
return SelectProcedure(procedureName, inputParameters, out dataTable, false);
else NotifyException(ex);
return false;
}
finally
{
Cursor.Current = Cursors.Default;
}
}

@firebird-automations
Copy link
Author

Commented by: @luronumen

Suggestion:
Redirect this Unhandled exception to FbException.ErrorCode = 335544721 (Unable to complete network request to host "@1")

@firebird-automations
Copy link
Author

Commented by: @luronumen

Hi Jiri,

Any news about this bug?
I'm sorry to be bothering you about this issue, but it is because with the pandemic many people working from home have reported more often about this unhandled exception.
As it is an intermittent bug, it might be interesting to be fixed some time before the release of the next version of the http://ADO.NET library so that I could help you with the validation, reporting that after weeks of using the library with the fix, the issue was not more reproducible.

Best Regards,
Luciano

@firebird-automations
Copy link
Author

Commented by: @cincuranet

At the moment I'm working on finishing the v8.0. I'll fix that maybe into 8.0 maybe into next version. Seems straightforward enough to put it into 8.0, we'll see.

@firebird-automations
Copy link
Author

Commented by: @luronumen

Thank you very much for your understanding, Jiri!

Best Regards,
Luciano

@firebird-automations
Copy link
Author

Commented by: @luronumen

This issue is reproducible in version 8.0.0-alpha3 but the error message is slightly different:

========================================
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
FirebirdSql.Data.Common.IscException: Error writing data to the connection.
Error reading data from the connection. ---> System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at FirebirdSql.Data.Common.AsyncWrappingCommonArgs.SyncTaskCompleted[TTask,T1,T2,T3](TTask completed, Action`3 sync, T1 arg1, T2 arg2, T3 arg3)
at FirebirdSql.Data.Common.AsyncWrappingCommonArgs.AsyncSyncCall[T1,T2,T3](Func`5 asyncCall, Action`3 syncCall, T1 arg1, T2 arg2, T3 arg3)
at FirebirdSql.Data.Client.Managed.DataProviderStreamWrapper.Write(Byte[] buffer, Int32 offset, Int32 count, AsyncWrappingCommonArgs async)
at FirebirdSql.Data.Client.Managed.FirebirdNetworkHandlingWrapper.<Flush>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.<DoFreePacket>d__43.MoveNext()
--- End of inner exception stack trace ---
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.<DoFreePacket>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.Client.Managed.Version11.GdsStatement.<Free>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.Common.StatementBase.<Release>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.<Dispose2>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.FirebirdClient.FbCommand.<Release>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.FirebirdClient.FbCommand.<DisposeHelper>d__73.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at FirebirdSql.Data.FirebirdClient.FbCommand.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at CHRONOS.Models.Databases.FirebirdSQLDatabase.SelectProcedure(String procedureName, String[] inputParameters, DataTable& dataTable, Boolean poolingStatus)

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Fix Version: vNext [ 10982 ]

@cincuranet
Copy link
Member

@luronumen Would you mind trying this build to see everything behaves as expected?

@luronumen
Copy link

@luronumen Would you mind trying this build to see everything behaves as expected?

Hi @cincuranet

How can I download FirebirdSql.Data.FirebirdClient.dll from this site?
Could you generate an alpha version and publish it to https://www.nuget.org/packages/FirebirdSql.Data.FirebirdClient/ ?

First of all thank you very much for working to fix this issue!

@cincuranet
Copy link
Member

Both NuGet and the dll are in this.

@luronumen
Copy link

Both NuGet and the dll are in this.

Hi @cincuranet

The issue is still reproducible on this version. See: ERROR.txt

@cincuranet
Copy link
Member

That looks correct. Now the exception is FbException and should be handled accordingly (around FbCommand.Dispose).

@luronumen
Copy link

That looks correct. Now the exception is FbException and should be handled accordingly (around FbCommand.Dispose).

Hi @cincuranet

You mean this error has to be handled in my code?
Here is my code where the exception happens: SelectProcedure.txt

Do you know how I can improve it to catch this exception?

Thanks in advance,
Luciano

@cincuranet
Copy link
Member

Yes. You need the try-catch block around the fbCommand using block.

@luronumen
Copy link

Hi @cincuranet

You means like that: SelectProcedureNewVersion.txt

@cincuranet
Copy link
Member

Yes, that's one way to do it.

@cincuranet
Copy link
Member

Done in 836ba7a.

@luronumen
Copy link

Hi @cincuranet

I retested this issue using this build version and this SelectProcedureNewVersion.txt version and the issue is no longer reproducible!

Thank you very much for the fix!

Best Regards,
Luciano

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

No branches or pull requests

3 participants