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

ArgumentOutOfRangeException [DNET938] #861

Closed
firebird-automations opened this issue Apr 1, 2020 · 8 comments
Closed

ArgumentOutOfRangeException [DNET938] #861

firebird-automations opened this issue Apr 1, 2020 · 8 comments

Comments

@firebird-automations
Copy link

Submitted by: Krosaci (krosaci)

Hello, I ran on specific problem on Firebird net provider (ver. 6.4.0) . Sometimes (once or two times a month) on some machines provider throws after calling Begin Transaction ArgumentOutOfRangeException. Look at callstack:

System.ArgumentOutOfRangeException: operation=159
Parameter name: operation
at FirebirdSql.Data.Client.Managed.GdsConnection.ProcessOperation(Int32 operation, XdrStream xdr)
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadSingleResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadGenericResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsTransaction.BeginTransaction(TransactionParameterBuffer tpb)
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.BeginTransaction(TransactionParameterBuffer tpb)
at FirebirdSql.Data.FirebirdClient.FbTransaction.BeginTransaction(FbTransactionOptions options)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.BeginTransaction(FbTransactionOptions options, String transactionName)
at FirebirdSql.Data.FirebirdClient.FbConnection.BeginTransaction(FbTransactionOptions options)

Or sometimes it throws similar exception but with parameter operation =-16777216.
We are using Firebird server 2.5.4.

Thanks for any advice to resolve this issue.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

First try to replicate it with latest version, 6.4.0 is quite old.

@firebird-automations
Copy link
Author

Commented by: Christian Mayer (ascmayer)

Hi, we have the same issue with Verion 7.1.1.0

System.ArgumentOutOfRangeException: operation=509011189
Parametername: operation
bei FirebirdSql.Data.Client.Managed.GdsConnection.ProcessOperation(Int32 operation, IXdrReader xdr)
bei FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadSingleResponse(Int32 operation)
bei FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse[TResponse]()
bei FirebirdSql.Data.Client.Managed.Version10.GdsTransaction.BeginTransaction(TransactionParameterBuffer tpb)
bei FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.BeginTransaction(TransactionParameterBuffer tpb)
bei FirebirdSql.Data.FirebirdClient.FbTransaction.BeginTransaction()
bei FirebirdSql.Data.FirebirdClient.FbCommand.Prepare(Boolean returnsSet)
bei FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet)
bei FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior)
bei FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteDbDataReader(CommandBehavior behavior)
bei System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

The operation number varies.
Once this error appears, it seems to happen every time BeginTransaction is called, until we restart our application.

Thanks

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Can you replicate it?

@firebird-automations
Copy link
Author

Commented by: Christian Mayer (byzo_mc)

We tried to replicate it on our dev machines without success.
After running sfc /scannow - which found something to fix - the exception doesnt occur anymore.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

That's unfortunate. :( Thanks for the effort.

I'll close it for now and I'll reopen when somebody has the same problem and can provide more clues.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Cannot Reproduce [ 5 ]

@mdjorov
Copy link

mdjorov commented Dec 1, 2022

Hello.
Just started to receive this error in one of our applications two days ago.
We've manage to find what in our app was causing the problem so I'll try to describe the situation as much as I can.
Maybe it will help you.
But in our case it was with the async methods.

Our case is this - we have a stored procedure in our database that does some complex calculations.
At the end, the procedure returns 3 values. In other parts of our database we use it like this:

"EXECUTE PROCEDURE PROC1 (PARAMS) RETURNING_VALUES :A, :B, :C;

In our .net web api server we have an async method that execute this procedure and where the error occurred.

Because of the 3 returning values, we use the procedure like this;
First we are creating a new FbCommand with "EXECUTE PROCEDURE PROC1(@PARAM1, @PARAM2)"
and after that we add the parameters like this:

proc.Parameters.Add(new FbParameter("@PARAM1", FbDbType.Integer));
proc.Parameters.Add(new FbParameter("@PARAM2", FbDbType.Date));
proc.Parameters.Add("@A", FbDbType.Integer).Direction = ParameterDirection.Output;
proc.Parameters.Add("@B", FbDbType.Integer).Direction = ParameterDirection.Output;
proc.Parameters.Add("@C", FbDbType.VarChar).Direction = ParameterDirection.Output;

because we execute the procedure multiple times in one transaction and we want to save some time from constantly creating objects and parameters .

At some point in our code, we execute the command in an async method:

First we initiate procedure's parameters from method's parameters.

proc.Parameters["PARAM1"].Value = value1;
proc.Parameters["PARAM2"].Value = value2;

then we execute it:

await using var reader = await proc.ExecuteReaderAsync(); // we use reader, because we need all 3 values returned from the procedure and ExecuteScalar is not useful.

if (reader?.Read() != true)
{
    ..some other logic
   return;
}

var result = new ResultData()
{
	A = reader.GetValue<int>("A"),    // GetValue<T> is our extension method to find the ordinal value of a column by it's name. Not important for the problem. It's just for saving some code writing.
	B = reader.GetValue<int>("B"),
	C = reader.GetValue<string>("C"),
};

So two days ago, our QA team reported that one scenario started to give errors:
When the application is executed normally we've got this exception:

System.ArgumentOutOfRangeException
Message = operation=0 (Parameter 'operation').

The value for operation in the most cases is 0, but some times it's something random. During my debugging of the problem I've seen values like 435, 250666 and bigger.
The call stack for the exception is:

at FirebirdSql.Data.Client.Managed.GdsConnection.<ProcessOperationAsync>d__81.MoveNext()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.<ReadSingleResponseAsync>d__85.MoveNext()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.<ReadSingleResponseAsync>d__83.MoveNext()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.<ReadResponseAsync>d__77.MoveNext()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.<SafeFinishFetchingAsync>d__81.MoveNext()
at FirebirdSql.Data.Client.Managed.Version11.GdsStatement.<PrepareAsync>d__3.MoveNext()  // sometimes this row is doubled
at FirebirdSql.Data.FirebirdClient.FbCommand.<PrepareAsync>d__126.MoveNext()
at FirebirdSql.Data.FirebirdClient.FbCommand.<PrepareAsync>d__126.MoveNext()
at FirebirdSql.Data.FirebirdClient.FbCommand.<ExecuteCommandAsync>d__128.MoveNext()
at FirebirdSql.Data.FirebirdClient.FbCommand.<ExecuteReaderAsync>d__88.MoveNext()
at FirebirdSql.Data.FirebirdClient.FbCommand.<ExecuteReaderAsync>d__88.MoveNext()

The Fb's client's version when this began was 9.0.2. We've updated it to 9.1.0 - but the error was still there.
The code above was not changed for almost 2 years.

So I've started to debug the problem.
The first thing that I noticed was, that if I set a break point in VS 2022 at a line before ExecuteReader's call at some of the parameters initialization and use F10 for step over and then Continue the error is gone. If I stop at the break point and hit Continue directly - the error occur.

So I've decided to add at the beginning of the method simple await Task.Delay(100);
This made the error gone.

At the same time the QA team reported that all other scenarios using this method are working just fine. They didn't have the "fix", they were still using the unmodified code.
So I've began to search for changes in the code for that specific scenario.
And I've found that another async method called before this one was changed.

in the main method both methods are called like this

await Method1(some params); // this one was changed
await ProblematicMethod(some params); //where the error occur

The first method is used to add an array of elements into the database, calling another async method for each element like this:

Method1()
{
 ......
  foreach (var element in elements)
  {
    await AddElementClass.AddAsync(params);
  }
.....
}

The change made in it was removing the await keyword from the AddAsync call

{
 ......
  foreach (var element in elements)
  {
    AddElementClass.AddAsync(params);
  }
.....
}

After returning it to its old version with await, the error in the second method was gone and the awat Task.Delay(100) was no longer necessary.

I don't know if this will help you to find the problem, but maybe it will be helpful clue for others that get this error in the future to find problems in their code.

@cincuranet
Copy link
Member

It's basically some as #963. The last part of your description is simply missing await. That could cause that. But that's simple programming error.

Anyway, if you have a valid reproducible scenario, feel free to drop the code into #963.

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