adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
531 stars 128 forks source link

arsd-mysql: litle mysql browser using vibe.d and arsd-mysql.d crashes after a view requests #267

Closed EmTee70 closed 3 years ago

EmTee70 commented 3 years ago

Hi, Adam I wrote a small tool (like a simple and fast replacement for phpmyadmin) to browse my mysql databases. I was using https://code.dlang.org/packages/mysql-d which was working stable, but because of several deprecation warnings i switched to your arsd-mysql.d Now the tool starts working but crashes after several browser requests. With a core dump. What can I do to find out the reason - I am not used to use the debugger but willing learn. How to start? And it seems to be depending on the size of the requested data, too. Any hint?

adamdruppe commented 3 years ago

Easiest way is to compile with -g (or dub's debug build option) and then run the program from inside gdb like this

gdb --args ./your_program any args it needs

First thing you need to do in here is disable the debugger catching with the GC pauses it. Assuming you on linux, paste these two lines in:

handle SIGUSR1 noprint
handle SIGUSR2 noprint

Now you are ready to go. It will give you a prompt and type "r" (for "run").

Then go to the browser and do what you need to do to make it crash.

Then go back to the debugger, it should say something like "signal received SIGSEGV" and be at a prompt again. Now you can type "where" and it should spit out the line where it failed and a stack trace.

That might be enough for you to see where the bug is yourself, or you can paste it in here and I'll see if it makes any sense to me too.

I've done a bunch of larger data sets with mysql in the past with this lib... but nothing recently. Back when they put out MySQL version 5.1, it was a breaking change on the binary layout of data, so you had to use a version specifier when building. But that was so long ago you surely don't have an old version....... but possible a new version did a similiar change.

What database version do you have?

Of course also possible it is just a plain old bug I messed up on.

EmTee70 commented 3 years ago

Thank you a lot! I have: mysql --version mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper

EmTee70 commented 3 years ago

Hmm: [New Thread 0x7ffff7fd5700 (LWP 18295)] [New Thread 0x7ffff7e16700 (LWP 18296)] [New Thread 0x7ffff7e0f700 (LWP 18297)]

Thread 1 "mysql-browse" received signal SIGSEGV, Segmentation fault. 0x00007ffff787dbca in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20

Should I go further and install the debug symbols for mysql: as mentioned here ? https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1818985

I will check it out on my notebook, updating it to Ubuntu 20.04. and a newer mysqlclient, if this helps I will do the same for my server. The only strange thing is, that the other mysql-d lib was working without problems.

adamdruppe commented 3 years ago

Did the where command give any more info? The problem is almost certainly a higher level than that.

(i think the other mysql lib doesn't use the same client at all btw)

EmTee70 commented 3 years ago

yes:

0 0x00007ffff787dbca in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20

1 0x00007ffff7843455 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20

2 0x00007ffff7848550 in mysql_close () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20

3 0x00005555559cbeb5 in arsd.mysql.MySql.close() (this=0x7ffff7ec04b0)

at ../../.dub/packages/arsd-official-8.5.2/arsd-official/mysql.d:232

4 0x00005555559cbecf in arsd.mysql.MySql.~this() (this=0x7ffff7ec04b0)

at ../../.dub/packages/arsd-official-8.5.2/arsd-official/mysql.d:236

5 0x0000555555bbde74 in rt_finalize2 ()

6 0x0000555555c5946b in rt_finalizeFromGC ()

7 0x0000555555c523be in _D2gc4impl12conservativeQw3Gcx5sweepMFNbZm ()

8 0x0000555555c52e62 in _D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()

9 0x0000555555c50f41 in _D2gc4impl12conservativeQw3Gcx10smallAllocMFNbmKmkxC8TypeInfoZPv ()

10 0x0000555555c5693d in _D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQFcMFNbKmKkKmKxQDsZQDl ()

11 0x0000555555c4e6aa in D2gc4impl12conservativeQw14ConservativeGC6qallocMFNbmkxC8TypeInfoZS4core6memory8BlkInfo ()

12 0x0000555555bb9ad7 in gc_qalloc ()

13 0x0000555555bbdc68 in _d_newitemT ()

14 0x00005555559c20f4 in _D3std5arrayT8AppenderTAyaZQo6ctorMFNaNbNcNeQxZSQByQBx__TQBuTQBoZQCc (this=..., arr=...)

at /usr/include/dmd/phobos/std/array.d:3249

15 0x0000555555b5d4cc in _D3std5arrayT8appenderTAyaZQoFNaNbNfZSQBmQBlT8AppenderTQBiZQo ()

at /usr/include/dmd/phobos/std/array.d:3853

16 0x00005555559caaa9 in _D3std4convT5toStrTAyaTSQy5rangeT4TakeTQwZQjZQBjFNaNfQBgZQBo (src=...)

at /usr/include/dmd/phobos/std/conv.d:150

17 0x00005555559caa96 in _D3std4convT6toImplTAyaTSQz5rangeT4TakeTQwZQjZQBkFNaNfQBgZQBo (value=...)

at /usr/include/dmd/phobos/std/conv.d:1050

18 0x00005555559caa7a in _D3std4convT2toTAyaZTQlTSQBb5range__T4TakeTQBdZQkZQBoFNaNfQBiZQBw (_param_0=...)

at /usr/include/dmd/phobos/std/conv.d:223

19 0x00005555559caa5e in _D3std4convT8textImplTAyaTSQBb5rangeT4TakeTQxZQjZQBnFNaNfQBhZQBp (_param_0=...)

at /usr/include/dmd/phobos/std/conv.d:4195

20 0x00005555559caa42 in _D3std4convT4textTSQt5rangeT4TakeTAyaZQkZQBfFNaNfQBhZQt (_param_0=...)

at /usr/include/dmd/phobos/std/conv.d:4150

21 0x00005555559ca433 in _D5mylib9subStringFAyammZQg (end=50, beg=0, s=...) at ../mylib/source/mylib.d:103

22 0x00005555559c1e66 in _D5mylib4leftFAyamZQf (last=50, s=...) at ../mylib/source/mylib.d:107

23 0x00005555559bd304 in _D4diet4htmlT25compileHTMLDietFileStringVAyaa13_73686f775f7461626c652e6474S_DQCzQCxT13_di

EmTee70 commented 3 years ago

The old lib was based on your code: mysql library binding. Extraction from https://github.com/adamdruppe/arsd

EmTee70 commented 3 years ago

Your old arsd version of close was:

void close() {
        if (mysql) {
            mysql_close(mysql);
            mysql = null;
        }
    }

now:

void close() {
                mysql_close(mysql);
}

May be mysql can be undefined and than... dump?

adamdruppe commented 3 years ago

oh that must explain it. on my copy that code has never been changed - the person who forked it must have already noticed and fixed this bug!

I just pushed it, you should try making the change on your copy too then see if it fixes your problem too.

EmTee70 commented 3 years ago

It works! Thank you for teaching me!

adamdruppe commented 3 years ago

yay! that was easier than I thought it would be lol, just a plain missing null check :)

EmTee70 commented 3 years ago

I am very happy, that my mysql-browse now relies on a maintained package. In the moment I have increased the scope of the program to do some other special tasks for me. But I may reduce it to the pure mysql-browser again and put it on github. Because it is simple and fast I get a table and/or database info request rendered in 120ms and not in more than a second with phpmyadmin. (and you don't need a login in what saves most). It was my fist useful D program and I love the quick response, always when I need to know table or field names or type of one of our many mysql tables. So thank you again for your lib!

adamdruppe commented 3 years ago

yeah let me know if you need more, i haven't used this module for a while so there are probably some missing spots