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
Operations

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 all.zip (513 kB)
2. Zip Archive Fast.zip (436 kB)
3. File structure.sql (0.9 kB)
4. Zip Archive UdfCrash.zip (223 kB)
5. Zip Archive WpfApp1.zip (10 kB)

Environment: win64 / fb3 64
Issue Links:
Duplicate
 

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
attached

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

Alexander Muylaert-Gelein made changes - 07/Jun/17 06:30 PM
Field Original Value New Value
Attachment all.zip [ 13133 ]
kdv added a comment - 07/Jun/17 06:48 PM
You forgot
IsMultiThread:=True;
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
Hi

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

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

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 made changes - 07/Jun/17 07:19 PM
Attachment Fast.zip [ 13134 ]
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

a

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

Alexander Muylaert-Gelein made changes - 07/Jun/17 07:29 PM
Attachment structure.sql [ 13135 ]
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";
                    cmd.ExecuteNonQuery();
                    tr.Commit();
                }
            }
        }

        void Explode()
        {
            using (var con = new FbConnection(dbs[m_Random.Next(dbs.Count)]))
            {
                con.Open();
                UpdateDate(con);
            }
        }

Vlad Khorsun made changes - 07/Jun/17 07:55 PM
Assignee Vlad Khorsun [ hvlad ]
Alexander Muylaert-Gelein added a comment - 07/Jun/17 08:06 PM
Hi,

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

Alexander

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

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

thanks

Alexander

Alexander Muylaert-Gelein made changes - 08/Jun/17 05:56 AM
Attachment UdfCrash.zip [ 13136 ]
Attachment WpfApp1.zip [ 13137 ]
Vlad Khorsun added a comment - 08/Jun/17 06:24 AM
Thanks, i reproduced it.

Alexander Peshkov made changes - 08/Jun/17 09:39 AM
Assignee Vlad Khorsun [ hvlad ] Alexander Peshkov [ alexpeshkoff ]
Alexander Peshkov made changes - 08/Jun/17 09:45 AM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 4.0 Alpha 1 [ 10731 ]
Fix Version/s 3.0.3 [ 10810 ]
Resolution Fixed [ 1 ]
Mark Rotteveel made changes - 08/Jun/17 03:26 PM
Link This issue is duplicated by CORE-5560 [ CORE-5560 ]
Mark Rotteveel made changes - 08/Jun/17 03:27 PM
Link This issue is duplicated by CORE-5561 [ CORE-5561 ]
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?

thanks

Alexander

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

Pavel Zotov made changes - 22/Jun/17 10:43 AM
Status Resolved [ 5 ] Resolved [ 5 ]
Test Specifics [Platform (Windows/Linux) specific]
QA Status No test Cannot be tested
Pavel Zotov made changes - 22/Jun/17 10:43 AM
Status Resolved [ 5 ] Closed [ 6 ]