Last active
March 23, 2019 14:41
-
-
Save hirose31/3440065a7bdc9d77f1c70ec8bc007ad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#0 yaSSL::SSL::GetError (this=this@entry=0x56295bf4df70) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/extra/yassl/src/yassl_int.cpp:1520 | |
#1 0x00007f48640aa5db in yaSSL::receiveData (ssl=..., data=..., | |
peek=peek@entry=false) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/extra/yassl/src/handshake.cpp:1047 | |
#2 0x00007f48640901ed in yaSSL::yaSSL_read (ssl=ssl@entry=0x56295bf4df70, | |
buffer=buffer@entry=0x56295bf500f0, sz=sz@entry=4) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/extra/yassl/src/ssl.cpp:363 | |
#3 0x00007f4864069987 in vio_ssl_read (vio=0x56295bf49590, | |
buf=0x56295bf500f0 "r", size=<optimized out>) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/vio/viossl.c:186 | |
#4 0x00007f4864042d8e in net_read_raw_loop (count=4, net=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:672 | |
#5 net_read_packet_header (net=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:762 | |
#6 net_read_packet (net=0x56295bf4d0a0, complen=0x7fff3bfc7760) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:822 | |
#7 0x00007f4864043e0c in my_net_read (net=net@entry=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:899 | |
#8 0x00007f486403809c in cli_safe_read_with_ok ( | |
mysql=mysql@entry=0x56295bf4d0a0, parse_ok=parse_ok@entry=0 '\000', | |
is_data_packet=is_data_packet@entry=0x0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:1061 | |
#9 0x00007f486403834f in cli_safe_read (mysql=mysql@entry=0x56295bf4d0a0, | |
is_data_packet=is_data_packet@entry=0x0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:1194 | |
#10 0x00007f4864039168 in cli_read_query_result (mysql=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:5245 | |
#11 0x00007f486403af31 in mysql_real_query (mysql=mysql@entry=0x56295bf4d0a0, | |
query=query@entry=0x7fff3bfc78a0 "SELECT id,origin,ns,mbox,serial,refresh,retry,expire,minimum,ttl FROM soa WHERE origin='foo.example.com.'", | |
length=<optimized out>) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:5341 | |
#12 0x000056295ac210d9 in sql_query (sqlConn=sqlConn@entry=0x56295bf4d0a0, | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:822 | |
#7 0x00007f4864043e0c in my_net_read (net=net@entry=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql/net_serv.cc:899 | |
#8 0x00007f486403809c in cli_safe_read_with_ok ( | |
mysql=mysql@entry=0x56295bf4d0a0, parse_ok=parse_ok@entry=0 '\000', | |
is_data_packet=is_data_packet@entry=0x0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:1061 | |
#9 0x00007f486403834f in cli_safe_read (mysql=mysql@entry=0x56295bf4d0a0, | |
is_data_packet=is_data_packet@entry=0x0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:1194 | |
#10 0x00007f4864039168 in cli_read_query_result (mysql=0x56295bf4d0a0) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:5245 | |
#11 0x00007f486403af31 in mysql_real_query (mysql=mysql@entry=0x56295bf4d0a0, | |
query=query@entry=0x7fff3bfc78a0 "SELECT id,origin,ns,mbox,serial,refresh,retry,expire,minimum,ttl FROM soa WHERE origin='foo.example.com.'", | |
length=<optimized out>) | |
at /export/home/pb2/build/sb_0-32013917-1545389775.79/release/mysql-5.7.25/sql-common/client.c:5341 | |
#12 0x000056295ac210d9 in sql_query (sqlConn=sqlConn@entry=0x56295bf4d0a0, | |
---Type <return> to continue, or q <return> to quit--- | |
query=query@entry=0x7fff3bfc78a0 "SELECT id,origin,ns,mbox,serial,refresh,retry,expire,minimum,ttl FROM soa WHERE origin='foo.example.com.'", | |
querylen=<optimized out>) at sql.c:332 | |
#13 0x000056295ac209f7 in mydns_soa_load (sqlConn=0x56295bf4d0a0, | |
rptr=rptr@entry=0x7fff3bfc7b38, | |
origin=origin@entry=0x56295bf97900 "foo.example.com.") at soa.c:270 | |
#14 0x000056295ac0bbc8 in zone_cache_find (t=t@entry=0x56295bf97880, | |
zone=zone@entry=0, origin=origin@entry=0x0, type=type@entry=DNS_QTYPE_SOA, | |
name=name@entry=0x56295bf97900 "foo.example.com.", | |
namelen=namelen@entry=24, errflag=0x7fff3bfc7bb4, parent=0x0) | |
at cache.c:596 | |
#15 0x000056295ac0de1d in find_soa (t=t@entry=0x56295bf97880, | |
fqdn=fqdn@entry=0x56295bf97900 "foo.example.com.", | |
label=label@entry=0x7fff3bfc7c50 "") at data.c:56 | |
#16 0x000056295ac164ca in resolve (t=t@entry=0x56295bf97880, | |
section=section@entry=ANSWER, qtype=DNS_QTYPE_A, | |
fqdn=fqdn@entry=0x56295bf97900 "foo.example.com.", | |
level=level@entry=0) at resolve.c:432 | |
#17 0x000056295ac1a096 in task_process (t=0x56295bf97880) at task.c:541 | |
#18 0x000056295ac098d8 in main (argc=<optimized out>, argv=<optimized out>) | |
at main.c:886 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- mode: c; coding: utf-8 -*- | |
How to reproduce | |
gcc infinite-loop.c $(mysql_config --cflags) $(mysql_config --libs) -o infinite-loop | |
MYSQL_USER=scott MYSQL_PWD=tiger ./infinite-loop | |
mysql client version: 50725 | |
> safe_sleep: 20 | |
caught signal: 10 | |
> do_query | |
(entering an infinite loop) | |
^C | |
mysql client version: 50620 | |
> safe_sleep: 20 | |
caught signal: 10 | |
> do_query | |
query: Lost connection to MySQL server during query | |
(not entering an infinite loop) | |
*/ | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <signal.h> | |
#include <time.h> | |
#include <mysql.h> | |
void signal_handler(int signum) { | |
fprintf(stderr, "caught signal: %d\n", signum); | |
} | |
void do_query(MYSQL mysql) { | |
int r; | |
MYSQL_RES *result; | |
MYSQL_ROW row; | |
fprintf(stderr, "> do_query\n"); | |
char *stmt = "select 1"; | |
unsigned int stmt_len = strlen(stmt); | |
r = mysql_real_query(&mysql, stmt, stmt_len); | |
if (r != 0) { | |
fprintf(stderr, "query: %s\n", mysql_error(&mysql)); | |
exit(1); | |
} | |
result = mysql_store_result(&mysql); | |
while ((row = mysql_fetch_row(result))) { | |
printf("< %s\n", row[0]); | |
} | |
mysql_free_result(result); | |
} | |
void safe_sleep(time_t sec) { | |
int r; | |
struct timespec req, rem; | |
fprintf(stderr, "> safe_sleep: %ld\n", sec); | |
req.tv_sec = sec; | |
req.tv_nsec = 0; | |
for (;;) { | |
r = nanosleep(&req, &rem); | |
if (r == 0) { | |
break; | |
} else { | |
req.tv_sec = rem.tv_sec; | |
req.tv_nsec = rem.tv_nsec; | |
} | |
} | |
} | |
int main(int argc, char** argv) { | |
int r; | |
char *host = getenv("MYSQL_HOST"); | |
char *user = getenv("MYSQL_USER"); | |
char *password = getenv("MYSQL_PWD"); | |
MYSQL mysql; | |
struct sigaction sa; | |
if (host == NULL) | |
host = "127.0.0.1"; | |
if (user == NULL) | |
user = "root"; | |
memset(&sa, 0, sizeof(sa)); | |
sa.sa_handler = signal_handler; | |
if (sigaction(SIGTERM, &sa, NULL) != 0) { | |
perror("sigaction"); | |
exit(1); | |
} | |
if (sigaction(SIGALRM, &sa, NULL) != 0) { | |
perror("sigaction"); | |
exit(1); | |
} | |
if (sigaction(SIGUSR1, &sa, NULL) != 0) { | |
perror("sigaction"); | |
exit(1); | |
} | |
fprintf(stderr, "mysql client version: %ld\n", mysql_get_client_version()); | |
mysql_init(&mysql); | |
// disable reconnection | |
my_bool reconnect = 0; | |
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect); | |
if (!mysql_real_connect(&mysql, host, user, password, "", 3306, NULL, 0)) { | |
fprintf(stderr, "connect: %s\n", mysql_error(&mysql)); | |
exit(1); | |
} | |
// must be greater than `wait-timeout` | |
int sleep_second = 20; | |
for (;;) { | |
if (fork() == 0) { | |
// char *signal = "-TERM"; | |
// char *signal = "-ALRM"; | |
char *signal = "-USR1"; | |
char p_pid[12]; | |
sprintf(p_pid, "%d", getppid()); | |
sleep(3); | |
execl("/bin/kill", "/bin/kill", signal, p_pid, (char *)NULL); | |
perror("failed to exec"); | |
exit(1); | |
} | |
safe_sleep(sleep_second); | |
sleep_second += 10; | |
do_query(mysql); | |
} | |
mysql_close(&mysql); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment