Bug #61544 mysql crashes on udf update
Submitted: 16 Jun 2011 18:01 Modified: 17 Jul 2011 19:08
Reporter: Dan L Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S3 (Non-critical)
Version:5.1.53 OS:Linux
Assigned to: CPU Architecture:Any

[16 Jun 2011 18:01] Dan L
Description:
I am trying to update several UDFs that are compiled separately from mysql. The functions work fine once they are installed, however mysql will crash every time the .so file is updated. The process used to update the UDFs is loosely like this:

- make udf
- run set of drop function statements within mysql to drop the udfs
- install udf (ie, make install to create the .so file in the mysql/plugin directory
- run set of create function statements within mysql to create udfs

Each time I get to re-creating the functions via sql, mysql crashes. I am following the directions from this page: http://dev.mysql.com/doc/refman/5.1/en/create-function-udf.html

By these directions from the note at the bottom, I should be able to update the .so file without having to restart the mysql server, correct? Is there something else I need to be doing here or is this a bug? 

Thanks for your help. 

How to repeat:
Follow the same procedure as described above assuming you have compiled and installed a .so file that has a set of user defined functions.
 
- drop all functions associated with the .so library
- re-install .so file
- then run create statements to create all functions associated with the new .so

The mysql server should crash at this pint.
[16 Jun 2011 21:18] MySQL Verification Team
Could you please test 5.1.57 version if still you get the crash attach the backtrace. Thanks.
[17 Jun 2011 14:45] Dan L
Hi, I tried with version 5.1.57, it looks like mysql crashed again. Here is the backtrace...

110617 10:16:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
110617 10:16:45 [Note] Plugin 'FEDERATED' is disabled.
110617 10:16:45 [Note] Event Scheduler: Loaded 0 events
110617 10:16:45 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.57'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
terminate called after throwing an instance of 'std::runtime_error'
  what():  couldn't create jvm
110617 10:38:16 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8384512
read_buffer_size=131072
max_used_connections=2
max_threads=151
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 338324 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x16f78cc0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x410580f8 thread_stack 0x40000
/usr/local/mysql/libexec/mysqld(my_print_stacktrace+0x29) [0x7e9e59]
/usr/local/mysql/libexec/mysqld(handle_segfault+0x288) [0x5da31c]
/lib64/libpthread.so.0 [0x36b340eb10]
/lib64/libc.so.6(gsignal+0x35) [0x36b2c30265]
/lib64/libc.so.6(abort+0x110) [0x36b2c31d10]
/usr/lib64/libstdc++.so.6(__gnu_cxx::__verbose_terminate_handler()+0x114) [0x36b54becb4]
/usr/lib64/libstdc++.so.6 [0x36b54bcdb6]
/usr/lib64/libstdc++.so.6 [0x36b54bcde3]
/usr/lib64/libstdc++.so.6 [0x36b54bceca]
/usr/local/mysql/lib/mysql/plugin/libudfchemistry.so [0x2aaaab6ddfd5]
/usr/local/mysql/lib/mysql/plugin/libudfchemistry.so [0x2aaaabb57e96]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x16fd1190): CREATE FUNCTION amw RETURNS REAL SONAME 'libudfchemistry.so'
Connection ID (thread ID): 5
Status: NOT_KILLED

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
110617 10:38:16 mysqld_safe Number of processes running now: 0
110617 10:38:16 mysqld_safe mysqld restarted
110617 10:38:16 [Note] Plugin 'FEDERATED' is disabled.
110617 10:38:16 [Note] Event Scheduler: Loaded 0 events
110617 10:38:16 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.57'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[17 Jun 2011 19:08] MySQL Verification Team
Thank you for the feedback. I couldn't repeat with current source tree and using the udf_esample. Are you able to provide an UDF test case code which makes repeatable the issue?. Thanks.
[17 Jul 2011 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[28 Jun 2017 22:28] Brian Leishman
I'm experiencing this exact issue on MySQL 5.7.18, Debian 8.8. 

Any of the UDF's that I use is causing exactly the situation that the OP described. In my environment, this UDF (https://github.com/juanmirocks/Levenshtein-MySQL-UDF/blob/master/levenshtein.c) was the first one I found this out with, and I've written my own since then that has the same problem, which I will also attach. 

This happens on each and every one of my MySQL servers.
[28 Jun 2017 22:29] Brian Leishman
ifempty, Custom MySQL UDF

Attachment: ifempty.c (text/plain), 3.96 KiB.