fast_ping: Avoid ping race condition crash issue

This commit is contained in:
Nick Peng
2021-08-23 14:19:22 +08:00
parent 7f1dc8a311
commit 772229c826
4 changed files with 15 additions and 6 deletions

0
package/linux/make.sh Normal file → Executable file
View File

View File

@@ -1774,10 +1774,10 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info, ch
}
// ? this cause ssl crash ?
// setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
// setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
// setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
// set_sock_keepalive(fd, 15, 3, 4);
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
set_sock_keepalive(fd, 15, 3, 4);
setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
setsockopt(fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));

View File

@@ -365,7 +365,12 @@ static void _fast_ping_close_host_sock(struct ping_host_struct *ping_host)
static void _fast_ping_host_put(struct ping_host_struct *ping_host)
{
if (!atomic_dec_and_test(&ping_host->ref)) {
int ref_cnt = atomic_dec_and_test(&ping_host->ref);
if (!ref_cnt) {
if (ref_cnt < 0) {
tlog(TLOG_ERROR, "invalid refcount of ping_host %s", ping_host->host);
abort();
}
return;
}
@@ -1081,15 +1086,19 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
pthread_mutex_unlock(&ping.map_lock);
_fast_ping_host_get(ping_host);
_fast_ping_host_get(ping_host);
// for ping race condition, get reference count twice
if (_fast_ping_sendping(ping_host) != 0) {
goto errout_remove;
}
ping_host->run = 1;
freeaddrinfo(gai);
_fast_ping_host_put(ping_host);
return ping_host;
errout_remove:
fast_ping_stop(ping_host);
_fast_ping_host_put(ping_host);
ping_host = NULL;
errout:
if (gai) {

View File

@@ -1045,7 +1045,7 @@ void print_stack(void)
}
tlog(TLOG_FATAL, "Stack:");
for (size_t idx = 0; idx < frame_num; ++idx) {
for (int idx = 0; idx < frame_num; ++idx) {
const void *addr = buffer[idx];
const char *symbol = "";