NETProvider icon indicating copy to clipboard operation
NETProvider copied to clipboard

Randomly arises strange error on connect NETProvider 8.5.4.0 to Fb 4.0.1 Error writing data to the connection

Open andrewkip opened this issue 3 years ago • 25 comments

FirebirdSql.Data.FirebirdClient.FbException (0x80004005): Error writing data to the connection. Error reading data from the connection. ---> FirebirdSql.Data.Common.IscException: Error writing data to the connection. Error reading data from the connection. ---> System.IO.IOException: Missing 4 bytes to fill total 4. в FirebirdSql.Data.Client.Managed.XdrReaderWriter.ReadBytes(Byte[] buffer, Int32 count) в FirebirdSql.Data.Client.Managed.XdrReaderWriter.ReadOperation() в FirebirdSql.Data.Client.Managed.AuthBlock.ProcessContAuthResponse(IXdrReader xdr) в FirebirdSql.Data.Client.Managed.GdsConnection.Identify(String database) --- Конец трассировки внутреннего стека исключений --- в FirebirdSql.Data.Client.Managed.GdsConnection.Identify(String database) в FirebirdSql.Data.Client.ClientFactory.CreateManagedDatabase(ConnectionString options) в FirebirdSql.Data.Client.ClientFactory.CreateDatabase(ConnectionString options) в FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect() в FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect() в FirebirdSql.Data.FirebirdClient.FbConnection.Open()

andrewkip avatar Jan 17 '22 12:01 andrewkip

Can you replicate it?

cincuranet avatar Jan 17 '22 12:01 cincuranet

Can you replicate it?

I'll try

andrewkip avatar Jan 17 '22 12:01 andrewkip

The error has gone - antivirus Esset is under suspicion.

Sorry.

andrewkip avatar Jan 20 '22 08:01 andrewkip

OK. In case it returns and you have some way to simulate it, let me know.

cincuranet avatar Jan 20 '22 08:01 cincuranet

Hey @cincuranet Hope it is okay to add a comment to the otherwise closed bug. This error happende to me as well during a trail upgrade of the provider. Stacktrace is the same as andrewkip experienced. I my envioment it happend on 4 servers connecting to Firebird 3.0.7. our log contains 800 entrys during 35 days, så it is quite rare. Perhaps a kind of loadtest where connectionpooling is disabled can reproduce the error, since it seems to happen in authentication.

realic avatar Mar 24 '22 22:03 realic

Sure. If you can create some load test, I'm happy to run it and see what's what.

cincuranet avatar Mar 25 '22 06:03 cincuranet

Hi.I have the same problem after upgrade from .NET 3.1 to NET 6 (Fb Core provider from v7.5.0 to 9.0.1) I've create sample app in VS 2022 Angular+NET6 new project +Serilog I've created one FB 3 database with one table,TEST.FDB password for db is in MydbContextcs.cs (connection string) I've created a new action in the controller

[ApiController]
  public class WeatherForecastController : ControllerBase
......................
      [HttpGet]
      [Route("api/[controller]")]
      public async Task<IActionResult> GetApi()
      {

          F_PAR? res = await db.F_PAR.FirstOrDefaultAsync(p => p.NR_ORD == 1);

          if (res == null)
          {
              return BadRequest();
          }
          else {
              return Ok(res);
          }
      }

I've put it on my vps(windows 2016 server,FB 3.0.9 superserver) and done some requests from Postman: http://myserver.com:83/api/weatherforecast

after 10 requests got the error "FirebirdSql.Data.Common.IscException: Error writing data to the connection." in link above there is file webapi-20220608.log from Serilog with my test

thanks

mrjohnr avatar Jun 08 '22 11:06 mrjohnr

Let me see whether I'll be able to reproduce it on my side.

cincuranet avatar Jun 20 '22 08:06 cincuranet

for me it occurs only on production server, not on local dev

mrjohnr avatar Jun 20 '22 17:06 mrjohnr

Hello,

I am happy to infrorm you that I was able to reproduce this behavior on my side. This behavior occurs pretty stable when connecting/disconneting to a database from different threads simultenously. I would like to note that I was able to reproduce this behavior using a linux database server only. As I can see, the issue does not occur when using a local database.

In the attachment you can find my small sample replicating the issue. All you need is to enter database credentials to corresponding text boxes, also enter the count of threads and duration between connecting/disconnecting. Then, click the OK button. On my side the issue sometimes can occur immediatelly, or after a couple of changing the threads and/or duration values.

We use a database with the following config: mtd_vts = /DATA_HDD/fb/mtd/mtd_vts.fdb { LockMemSize = 64M # We know that bigdb needs a lot of locks UserManager = Legacy_UserManager, Srp }

The Firebird version is 4.0.1 amd64 on linux. The Firebird.config is also in the attachment. Firebird.zip

Please try to reproduce the issue. If you need anything else, let me know.

AlexGreenZ avatar Jun 23 '22 15:06 AlexGreenZ

Hey With the information providede by Alex, I was also able to reproduce the problem. The problem did not occur when connecting the a server running on localhost. My program to reproduce the problem(race condition?) is a simple app that starts 40 threads and makes a lot of concurrent query's with connection pooling disabled.

Server on localhost is 3.0.5 running windows 10 Remote server is 3.0.10 running Linux.

realic avatar Jun 24 '22 22:06 realic

any news about that issue?

Let me see whether I'll be able to reproduce it on my side.

mrjohnr avatar Jul 04 '22 12:07 mrjohnr

@AlexGreenZ I wasn't able to replicate the issue with your setup and code.

cincuranet avatar Jul 06 '22 12:07 cincuranet

@mrjohnr I wasn't able to replicate the issue with your setup and code.

cincuranet avatar Jul 06 '22 13:07 cincuranet

too bad.I'm very sure there is a problem in recent versions of provider.A year ago I've tried to migrate to .NET 5 but users complains that app sometimes is not working,rolled back to 3.1 and app was working.this year tried to migrate to .NET 6 but the same complains from users,rolled back to 3.1 and no issue I hope it will be fixed until December 13, 2022(end of support for .NET 3.1) .

Thanks for your time!

@mrjohnr I wasn't able to replicate the issue with your setup and code.

mrjohnr avatar Jul 09 '22 13:07 mrjohnr

Hey @cincuranet Did you test it against a remote server, and not using localhost? The common denominator seems to be when connecting to a remote host, maybe even only on Linux servers.

realic avatar Jul 25 '22 16:07 realic

Yes, in both cases I was running instance on a separate machine (even outside local network).

cincuranet avatar Jul 25 '22 16:07 cincuranet

Hi I have the same issue only on production server NET 6(not 3.1),NETProvider version:9.1.0.0(.NET 6) /7.5.0(.NET 3.1),Firebird version 3.0.10,Windows server 2016. I've made a test on dev computer with direct connection to production server and no problem,seems that only running from IIS got the issue, is any special configuration to be done in IIS with NET 6+FB?

ionutIc avatar Nov 09 '22 09:11 ionutIc

is any special configuration to be done in IIS with NET 6+FB

None that I'm aware of.

cincuranet avatar Nov 09 '22 09:11 cincuranet

The same error can be reproduce with my sample on #963 I think that somehow both errors are related, because sporadically this error in this ticket is presented

NicFT avatar Dec 21 '22 12:12 NicFT

I've tested today this issue with NET 7+NETProvider v9.2.0 alpha 1 and seems to be fixed

mrjohnr avatar Jul 11 '23 15:07 mrjohnr

Hello! I may have found the solution to the problem, please take a look.

image

#if NET5_0_OR_GREATER

		socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 5);
		socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 5);
		socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 5);

#endif

It might be more optimal with different values.

My Error: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): Error writing data to the connection. Error reading data from the connection. ---> 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 established connection was aborted by the software in your host machine.. ---> System.Net.Sockets.SocketException (10053): An established connection was aborted by the software in your host machine.

Igor-9309 avatar Nov 11 '23 23:11 Igor-9309

@Igor-9309 Your problem is unrelated. The 10053 (similar to 10054) error is "normal" error that you should handle.

cincuranet avatar Nov 14 '23 11:11 cincuranet

@cincuranet Is there an error in my code then?

Igor-9309 avatar Nov 14 '23 16:11 Igor-9309

@Igor-9309 If you're not handling that case, then yes.

cincuranet avatar Nov 14 '23 16:11 cincuranet