Issue Details (XML | Word | Printable)

Key: CORE-5562
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Alexander Peshkov
Reporter: Alexander Muylaert-Gelein
Votes: 0
Watchers: 4

If you were logged in you would be able to see more operations.
Firebird Core

Firebird crashes when UDF (Delphi?) gets loaded and unloaded frequently

Created: 07/Jun/17 06:27 PM   Updated: 22/Jun/17 10:43 AM
Component/s: Engine
Affects Version/s: 3.0.2
Fix Version/s: 4.0 Alpha 1, 3.0.3

File Attachments: 1. Zip Archive (513 kB)
2. Zip Archive (436 kB)
3. File structure.sql (0.9 kB)
4. Zip Archive (223 kB)
5. Zip Archive (10 kB)

Environment: win64 / fb3 64
Issue Links:

QA Status: Cannot be tested
Test Specifics: Platform (Windows/Linux) specific

 Description  « Hide
Engine crashes when you frequently load and unload UDF dll in firebird. Especially when you're accessing multiple databases.

To reproduce

1. Copy the fast.dll to the udf folder.
2. copy multiple versions of the test.fdb to "d:\1\test.Fdb", "d:\2\test.fdb" ... "d:\10\test.fdb"
3. Launch firebird
4. Run the attached app. Or basically, Open a connection, execute the UDF function, close the connection.

Do this with multiple threads on multiple databases. The firebird process will crashes within 10 minutes with an access violation.

Workaround is to open another database that uses the udf. As long as the dll stays in memory, no crashes. As soon as it is unloaded, you have a fair chance that it crashes.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alexander Muylaert-Gelein added a comment - 07/Jun/17 06:30 PM

fast.dll => 64bit dll
dllcode.Zip => delphi code
wpfapp => app to simulate multiple connects, load dll, disconnects
test.Fdb => 3.0 db structure

kdv added a comment - 07/Jun/17 06:48 PM
You forgot
call in the initialization section of the DLL. Try this and check again.

And, you also forgot to specify
- DDL of function - if someone do not want to load the database. I hope it returns bigint by value.
- example of function call in SQL, if someone do not want to load application code (or don't care about used PL).

BTW, I could understand your request, if you had ready working UDF on 2.5, and it causes crash on 3.0. But if you created this especially for 3.0, who can guarantee that Delphi 64 compiler does not have bugs?

Alexander Muylaert-Gelein added a comment - 07/Jun/17 07:14 PM

Sorry, no, only forgot ismt in the example. I've been debugging 3 days on this and was able to bring it down to this tiny example.
I'll test it again.

We are porting our code from 2.5 to 3 and both the d64 compiler and the original dll didn't have this behavior.
It is only since we switched to fb3, that this is an issue.

kind regards


Alexander Muylaert-Gelein added a comment - 07/Jun/17 07:19 PM

This dll DOES set the IsMultithreaded to true. But results are the same. Also... there isn't much memory allocation hapening at all. All the function does is return.

I also tested FastMM, but that also suffered from the same problems.

Same dll under 2.5x has no problems.

kind regards

Alexander Muylaert-Gelein added a comment - 07/Jun/17 07:26 PM
Two more remarks

1. it doesn't seem to be so much a problem when you always open the "same" database. It happens most when you open many different fdb files in random or.
2. Firebird does not crash at all, if you keep on connection to whatever db that uses the dll open in for ex IBExpert.

kind regards


Alexander Muylaert-Gelein added a comment - 07/Jun/17 07:29 PM
structure to recreate database

Alexander Muylaert-Gelein added a comment - 07/Jun/17 07:31 PM

And some basic c# code on how to call the udf.

      Random m_Random = new Random();

        void UpdateDate(FbConnection aCon)
            using (var tr = aCon.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                using (var cmd = aCon.CreateCommand())
                    cmd.Transaction = tr;
                    cmd.CommandText = @"select version_start2() from rdb$database";

        void Explode()
            using (var con = new FbConnection(dbs[m_Random.Next(dbs.Count)]))

Alexander Muylaert-Gelein added a comment - 07/Jun/17 08:06 PM

Sorry for the additional two issues. I had some issues getting it comitted. it don't think the wifi is excellent here in the hotel in Sotchi.

kind regards


Vlad Khorsun added a comment - 07/Jun/17 09:54 PM

please, provide app in binary form.

Alexander Muylaert-Gelein added a comment - 08/Jun/17 05:56 AM
Hi Vlad

Please find attached windows binary in udfcrash
Source (in case somebody cares) in wpfApp1



Vlad Khorsun added a comment - 08/Jun/17 06:24 AM
Thanks, i reproduced it.

Alexander Muylaert-Gelein added a comment - 12/Jun/17 09:17 AM
Great and fast fix guys

Any idea when 3.0.3 is due?



Dmitry Yemanov added a comment - 12/Jun/17 09:28 AM
August-September, I believe.