When I was using smc_run to test mysql on x86 or arm64, the segfault issue occurred.
Use the gdb to parse the core file. The information is as follows:
(gdb) bt
0 0x0000000000000000 in ?? ()
1 0x00007f3cf0bd6374 in socket (domain=43, type=1, protocol=0) at smc-preload.c:117
2 0x00007f3cf058b05d in ?? () from /usr/lib64/mysql/libmysqlclient.so.21
3 0x00007f3cf0586249 in mysql_real_connect () from /usr/lib64/mysql/libmysqlclient.so.21
4 0x000000000041ac9c in mysql_drv_real_connect (db_mysql_con=db_mysql_con@entry=0x7f3cc8000e40) at drv_mysql.c:351
5 0x000000000041c24c in mysql_drv_connect (sb_conn=0x7f3cc8000db0) at drv_mysql.c:435
6 mysql_drv_connect (sb_conn=0x7f3cc8000db0) at drv_mysql.c:370
7 0x000000000040e781 in db_connection_create (drv=0x4a85c0 ) at db_driver.c:329
8 0x000000000043b956 in lj_vm_ffi_call ()
9 0x000000000045d09c in lj_ccall_func ()
10 0x00000000004379bd in lj_cf_ffi_meta___call ()
11 0x00000000004399b7 in lj_BC_FUNCC ()
12 0x0000000000427b0c in lua_pcall ()
13 0x0000000000414bdf in sb_lua_op_thread_init (thread_id=4) at sb_lua.c:461
14 0x000000000040c411 in worker_thread (arg=) at sysbench.c:809
15 0x00007f3cefe1b22a in ?? () from /usr/lib64/libc.so.6
16 0x00007f3cefe9dcf0 in ?? () from /usr/lib64/libc.so.6
The function pointed to by orig_socket is NULL.
The analysis is as follows:
CPUA CPUB
socket
initialize
dl_handle = dlopen(...
socket //dl_handle!=NULL
rc = (*orig_socket)(... //orig_socket is NULL,cause segfault
I think this issue occurs when users create sockets in multiple threads.
I'm not very familiar with smc-tool, and ask for help here.
I tried the following modifications to work around this problem, but it didn't solve the problem.
diff --git a/smc-preload.c b/smc-preload.c
index ee0ac83..83c5d80 100644
--- a/smc-preload.c
+++ b/smc-preload.c
@@ -96,6 +96,7 @@ static void set_bufsize(int socket, int opt, const char *envname) {
int socket(int domain, int type, int protocol)
{
int rc;
int cnt = 0;
if (!dl_handle)
initialize();
@@ -114,6 +115,16 @@ int socket(int domain, int type, int protocol)
domain = AF_SMC;
}
while (orig_socket == NULL && cnt < 10) {
usleep(10000);
cnt++;
}
if (orig_socket == NULL) {
printf("Failed to create socket, orig_socket is NULL\n");
When I was using smc_run to test mysql on x86 or arm64, the segfault issue occurred. Use the gdb to parse the core file. The information is as follows: (gdb) bt
0 0x0000000000000000 in ?? ()
1 0x00007f3cf0bd6374 in socket (domain=43, type=1, protocol=0) at smc-preload.c:117
2 0x00007f3cf058b05d in ?? () from /usr/lib64/mysql/libmysqlclient.so.21
3 0x00007f3cf0586249 in mysql_real_connect () from /usr/lib64/mysql/libmysqlclient.so.21
4 0x000000000041ac9c in mysql_drv_real_connect (db_mysql_con=db_mysql_con@entry=0x7f3cc8000e40) at drv_mysql.c:351
5 0x000000000041c24c in mysql_drv_connect (sb_conn=0x7f3cc8000db0) at drv_mysql.c:435
6 mysql_drv_connect (sb_conn=0x7f3cc8000db0) at drv_mysql.c:370
7 0x000000000040e781 in db_connection_create (drv=0x4a85c0) at db_driver.c:329
8 0x000000000043b956 in lj_vm_ffi_call ()
9 0x000000000045d09c in lj_ccall_func ()
10 0x00000000004379bd in lj_cf_ffi_meta___call ()
11 0x00000000004399b7 in lj_BC_FUNCC ()
12 0x0000000000427b0c in lua_pcall ()
13 0x0000000000414bdf in sb_lua_op_thread_init (thread_id=4) at sb_lua.c:461
14 0x000000000040c411 in worker_thread (arg=) at sysbench.c:809
15 0x00007f3cefe1b22a in ?? () from /usr/lib64/libc.so.6
16 0x00007f3cefe9dcf0 in ?? () from /usr/lib64/libc.so.6
The function pointed to by orig_socket is NULL. The analysis is as follows: CPUA CPUB socket initialize dl_handle = dlopen(... socket //dl_handle!=NULL rc = (*orig_socket)(... //orig_socket is NULL,cause segfault
I think this issue occurs when users create sockets in multiple threads.
I'm not very familiar with smc-tool, and ask for help here.
I tried the following modifications to work around this problem, but it didn't solve the problem. diff --git a/smc-preload.c b/smc-preload.c index ee0ac83..83c5d80 100644 --- a/smc-preload.c +++ b/smc-preload.c @@ -96,6 +96,7 @@ static void set_bufsize(int socket, int opt, const char *envname) { int socket(int domain, int type, int protocol) { int rc;
int cnt = 0;
if (!dl_handle) initialize(); @@ -114,6 +115,16 @@ int socket(int domain, int type, int protocol) domain = AF_SMC; }
while (orig_socket == NULL && cnt < 10) {
usleep(10000);
cnt++;
}
if (orig_socket == NULL) {
printf("Failed to create socket, orig_socket is NULL\n");
return -1;
}
rc = (*orig_socket)(domain, type, protocol); if (rc != -1) { set_bufsize(rc, SO_SNDBUF, "SMC_SNDBUF");