FirebirdSql.Data.Common.IscException: Error writing data to the connection

1,767 views
Skip to first unread message

Mrt John

unread,
May 31, 2022, 8:45:46 AM5/31/22
to firebird-n...@googlegroups.com
Hi.I've migrated one web app from .NET Core 3.1 to. NET 6, Fb Core provider from v7.5.0 to 9.0.1
new app works but sometimes doesn't start  on first run and got in console: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
After I reload it, works fine a while.
I've installed Seriog on production server and got that log:
...
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.
   at FirebirdSql.Data.Client.Managed.XdrReaderWriter.ReadBytesAsync(Byte[] buffer, Int32 count, CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.Managed.XdrReaderWriter.ReadInt32Async(CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.Managed.XdrReaderWriter.ReadOperationAsync(CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.Managed.AuthBlock.ProcessContAuthResponseAsync(CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.Managed.GdsConnection.IdentifyAsync(String database, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at FirebirdSql.Data.Client.Managed.GdsConnection.IdentifyAsync(String database, CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.ClientFactory.CreateManagedDatabaseAsync(ConnectionString options, CancellationToken cancellationToken)
   at FirebirdSql.Data.Client.ClientFactory.CreateManagedDatabaseAsync(ConnectionString options, CancellationToken cancellationToken)
   at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.ConnectAsync(CancellationToken cancellationToken)
   at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.ConnectAsync(CancellationToken cancellationToken)
   at FirebirdSql.Data.FirebirdClient.FbConnection.OpenAsync(CancellationToken cancellationToken)


 db connection settings:

  ob.UseFirebird("database=" + userSettings.Host + ":" + userSettings.Path + userSettings.DbName + ".fdb" +
             ";port=" + userSettings.Port +
             ";user=sysdba" +
             ";password=******" +
             ";Pooling=true" +
             ";Role=" +
             ";Dialect=3" +
             ";Charset=NONE" +
             ";ServerType=0" +
             ";Connection lifetime=15" +
             ";Packet Size=8192" +
             ";MinPoolSize=0" +
             ";MaxPoolSize=50" +
             ";WireCrypt=Enabled"
            );

found there a suggestion to disable connection pooling,

older app(NET 3.1+Fb core provider v7.5.0 ) works without any problem
is that a bug in my new app or I must disable connection pooling?

thanks



Gerdus van Zyl

unread,
May 31, 2022, 10:28:42 AM5/31/22
to firebird-n...@googlegroups.com
This error happens when the firebird server crashes or some network interruption.
Connection pooling usually makes this worse since it keeps old connections that are no longer valid/working around after firebird crash and you only find out when you try to use the connection.
You should handle the exception, clear the connection pool using  FbConnection.ClearAllPools  and retry the connection.

It is strange if it happens only when starting the app, maybe if firebird is also started at the same time, your app may be trying to connect before firebird is ready.


--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/CAK92MR_wqXWFnFMM%2Bq0FVCmzs87PC8%3DWviXfZY8OTq8pnuOi%3DA%40mail.gmail.com.

Mrt John

unread,
May 31, 2022, 11:11:30 AM5/31/22
to firebird-n...@googlegroups.com
Thanks for your answer,Fb version is 3.0.5,installed on a Windows Vps up 24/7,firebird is always started,there are other desktop app connected by vpn with  no problem
 reverting to .NET 3.1 all work fine.I had this problem since .NET 5,where I rolled back to 3.1
thanks



Mrt John

unread,
May 31, 2022, 1:17:05 PM5/31/22
to firebird-n...@googlegroups.com
@Gerdus: are you suggesting disabling pooling?

On Tue, May 31, 2022 at 5:28 PM Gerdus van Zyl <gerdus...@gmail.com> wrote:

Jiří Činčura

unread,
Jun 1, 2022, 2:38:24 AM6/1/22
to 'Mr. John' via firebird-net-provider
> older app(NET 3.1+Fb core provider v7.5.0 ) works without any problem

I would try to bisect the problem by changing only one variable. Either runtime first or provider (or vice versa).

> is that a bug in my new app or I must disable connection pooling?

Disabling connection pooling at this exact instance will not do anything. The exception happens when the connection is being opened for the first time (aka the connection is not from pool).

The exception was thrown simply because there wasn't enough data to read and that violates the protocol. Why is that happening is unclear so far.

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

Mrt John

unread,
Jun 1, 2022, 6:00:35 AM6/1/22
to firebird-n...@googlegroups.com
>I would try to bisect the problem by changing only one variable. Either runtime first or provider (or vice versa).
I think if I change the provider to v9 I have to change the runtime(v9 is compatible with .NET 6 only) or vice versa

thanks

--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.

Jiří Činčura

unread,
Jun 1, 2022, 6:40:01 AM6/1/22
to 'Mr. John' via firebird-net-provider
> I think if I change the provider to v9 I have to change the runtime(v9
> is compatible with .NET 6 only) or vice versa

Nope. You can use it on .NET Core 3.1 as well. You can check all the (transitively) supported versions here https://www.nuget.org/packages/FirebirdSql.Data.FirebirdClient in the Frameworks tab.

Mrt John

unread,
Jun 1, 2022, 6:55:52 AM6/1/22
to firebird-n...@googlegroups.com
tried,but got this:    Error NU1202 Package FirebirdSql.EntityFrameworkCore.Firebird 9.0.1 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package FirebirdSql.EntityFrameworkCore.Firebird 9.0.1 supports: net6.0 (.NETCoreApp,Version=v6.0)

>Nope. You can use it on .NET Core 3.1 as well. You can check all the (transitively) supported versions here https://www.nuget.org/packages/FirebirdSql.Data.FirebirdClient in the Frameworks tab.
--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.

Jiří Činčura

unread,
Jun 1, 2022, 7:14:24 AM6/1/22
to 'Mr. John' via firebird-net-provider
Yes, but that's EF Core.

Mrt John

unread,
Jun 4, 2022, 10:05:38 AM6/4/22
to firebird-n...@googlegroups.com
tried some suggestions found for that problem(update fb engine,increase connection lifetime,disabling pooling),but no fix.
no error found in firebird.log

is there any debugging I can do on my production server?

--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.

Jiří Činčura

unread,
Jun 4, 2022, 12:18:17 PM6/4/22
to 'Mr. John' via firebird-net-provider
> is there any debugging I can do on my production server?

Nothing specific from top of my head. Regular debugging, aka looking for a needle in a haystack.

Thomas Kragh

unread,
Jun 6, 2022, 5:57:05 PM6/6/22
to firebird-net-provider
Hey John? 
I am experiencing the same problem, in order to find some common denominator could you please send a version of your firebird.config. 
Especially the value of UserManager is interesting, as I use both Legacy_Manager and Srp on our server, perhaps this problem is with the Legacy Manager. 

Mrt John

unread,
Jun 7, 2022, 1:55:21 AM6/7/22
to firebird-n...@googlegroups.com
Hi
glad I'm not the only one with this problem,occurs very often making not possible to upgrade to .Net 6

thanks


--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.

Thomas Kragh

unread,
Jun 7, 2022, 3:32:31 AM6/7/22
to firebird-net-provider
Hey
So there is nothing interesting in your firebird.config since you only use Srp. Another user also had the same problem:  https://github.com/FirebirdSQL/NETProvider/issues/1021

I tried creating a load test in my codebase and also using the test suite from the firebird provider, but was unable to reproduce the error. Can you create a sample application that reproduces the problem, and share the code? 

Mrt John

unread,
Jun 7, 2022, 4:42:02 AM6/7/22
to firebird-n...@googlegroups.com
I'll try to create a sample but I'm afraid that problem occurs only on production machine

Mrt John

unread,
Jun 8, 2022, 7:34:44 AM6/8/22
to firebird-n...@googlegroups.com
Hi
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 

thanks

Thomas Kragh

unread,
Jun 10, 2022, 4:57:25 PM6/10/22
to firebird-net-provider
Hey
I was unfortunately unable to reproduce the exceptions that you get. I tried against a firebird server on my laptop(3.0.5) and a a development server (3.0.10 (snapshot build)), i even replaced the firebird config on my laptop with the one that you provided. 
I used two test patterns, one where connection lifetime was both smaller and larger that the time between requests, so that pooling and new connections was tested - about 3000 requests was made, but with no luck in reproducing the error. 

On the other hand, i was able to reproduce the problem on the codebase that i work on, over the last 4 days the error has occourd 7 times. The failing code, is a timer that is fired every minute to fetch changes from a table based on some timestamps, so in a day this will happen 1440 times, making this quite rare compared to your 1 in 10 requests. 

Thomas 

Mrt John

unread,
Jun 11, 2022, 9:19:38 AM6/11/22
to firebird-n...@googlegroups.com
@Thomas: hard to find a clue.for me only occurs on web server,not on dev machine.I'll stay on .working NET 3.1  :(

RDS Chauhan

unread,
Aug 19, 2022, 12:07:53 AM8/19/22
to firebird-net-provider
Some inputs.

I have a deployed application which i continue to upgrade where in the database keeps changing. So to deploy new version, i need to transfer data to the new database, where in table columns would have been added / removed; constraints changed, fields renamed etc.

Migration of data is a long process. During migration i also started to hit upon the same error, while transfering data using DataTable of ADO.NET.

I now copied the data from external database through calling a strored procedure in ADO.NET 

Now the error reported was very clear saying that a NOT NULL field is being assigned a NULL value.

So here it might be a case of upgraded stringent data validity checks, but error message not being clearly reported.

Please let me know if more details are required to be put here in my case.

.NET Framework 4.8.1
FirebirdSql.Data.FirebirdClient 9.0.2

connectionString=
       "User=SYSDBA; Password=masterkey;
        Database=D:\MtDataBase.FDB; DataSource=MyPC; Port=3050; Dialect=3; Charset=NONE;
        Role=Administrator; Compression=True; Connection Timeout=30; Connection lifetime=60;
        Pooling=true; MinPoolSize=0;MaxPoolSize=50; Packet Size=8192;ServerType=0;"

SELECT rdb$get_context ('SYSTEM', 'ENGINE_VERSION') from RDB$DATABASE;
3.0.9

Win 10

Regards,
Rajiv

Jiří Činčura

unread,
Aug 19, 2022, 3:43:13 AM8/19/22
to 'Mr. John' via firebird-net-provider
Can you create reproducible scenario? If so, send it.

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

>>>>>>> To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/d770ad90-aaac-4ada-bf7e-392200041513n%40googlegroups.com <https://groups.google.com/d/msgid/firebird-net-provider/d770ad90-aaac-4ada-bf7e-392200041513n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
>>>>> To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/75722d94-9e46-4e7c-ba61-72bcb812b156n%40googlegroups.com <https://groups.google.com/d/msgid/firebird-net-provider/75722d94-9e46-4e7c-ba61-72bcb812b156n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/29a894e0-fd3d-4e94-89a3-521cdf069af9n%40googlegroups.com <https://groups.google.com/d/msgid/firebird-net-provider/29a894e0-fd3d-4e94-89a3-521cdf069af9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "firebird-net-provider" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to firebird-net-pro...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/firebird-net-provider/e8aac324-82f3-477a-b7fa-f8fdee34148fn%40googlegroups.com
> <https://groups.google.com/d/msgid/firebird-net-provider/e8aac324-82f3-477a-b7fa-f8fdee34148fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Thomas Kragh

unread,
Aug 21, 2022, 3:51:10 PM8/21/22
to firebird-net-provider
Hey Rajiv
I hope you succeed in reproducing this error, however i wont put my money on null values being the problem, because all the times i have received the error have been during select. 
In this github issue, it has been suggested that its a race condition https://github.com/FirebirdSQL/NETProvider/issues/1021 when multiple connections are created from multiple threads. 

Does your migration job use multiple threads for moving the data? 

LtColRDSChauhan

unread,
Aug 21, 2022, 7:00:03 PM8/21/22
to firebird-n...@googlegroups.com


On Mon, 22 Aug 2022, 1:21 am Thomas Kragh, <famili...@gmail.com> wrote:
Hey Rajiv
I hope you succeed in reproducing this error, however i wont put my money on null values being the problem, because all the times i have received the error have been during select. 

I agree. 

Couple of years ago, i too received vague errors on simple select, which I did report here.

In this github issue, it has been suggested that its a race condition https://github.com/FirebirdSQL/NETProvider/issues/1021 when multiple connections are created from multiple threads. 

Does your migration job use multiple threads for moving the data? 

Yes.

You received this message because you are subscribed to a topic in the Google Groups "firebird-net-provider" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebird-net-provider/HGRC-OzEb8Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebird-net-pro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/9213d0c0-59fb-4131-973b-62a60e739f98n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages