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

Firebird crashes when UDF (Delphi?) gets loaded and unloaded frequently [CORE5562] #5829

Closed
firebird-automations opened this issue Jun 7, 2017 · 24 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Alexander Muylaert-Gelein (gonline)

Is duplicated by CORE5560
Is duplicated by CORE5561

Attachments:
all.zip
Fast.zip
structure.sql
UdfCrash.zip
WpfApp1.zip

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.

Commits: b80624c 68aa9c1

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

attached

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

@firebird-automations
Copy link
Collaborator Author

Modified by: Alexander Muylaert-Gelein (gonline)

Attachment: all.zip [ 13133 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @ibaseru

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?

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

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

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

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

@firebird-automations
Copy link
Collaborator Author

Modified by: Alexander Muylaert-Gelein (gonline)

Attachment: Fast.zip [ 13134 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

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

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

structure to recreate database

@firebird-automations
Copy link
Collaborator Author

Modified by: Alexander Muylaert-Gelein (gonline)

Attachment: structure.sql [ 13135 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

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\);
        \}
    \}

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

assignee: Vlad Khorsun [ hvlad ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

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

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Alexander,

please, provide app in binary form.

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

Hi Vlad

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

thanks

Alexander

@firebird-automations
Copy link
Collaborator Author

Modified by: Alexander Muylaert-Gelein (gonline)

Attachment: UdfCrash.zip [ 13136 ]

Attachment: WpfApp1.zip [ 13137 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Thanks, i reproduced it.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Vlad Khorsun [ hvlad ] => Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 4.0 Alpha 1 [ 10731 ]

Fix Version: 3.0.3 [ 10810 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Link: This issue is duplicated by CORE5560 [ CORE5560 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Link: This issue is duplicated by CORE5561 [ CORE5561 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexander Muylaert-Gelein (gonline)

Great and fast fix guys

Any idea when 3.0.3 is due?

thanks

Alexander

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

August-September, I believe.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Cannot be tested

Test Specifics: [Platform (Windows/Linux) specific]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment