diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2023-11-06 20:30:56 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2023-11-07 04:39:09 +0900 |
commit | d0066211f2052bf1444ffeb11544860a12cebff2 (patch) | |
tree | 4d000252cfa1909711f2c04092bd723d654e2427 /ext/socket | |
parent | 15560cce5f8709b8790bfde1528007c26654d168 (diff) |
Detach a pthread after pthread_setaffinity_np
After a pthread for getaddrinfo is detached, we cannot predict when the
thread will exit. It would lead to a segfault by setting
pthread_setaffinity to the terminated pthread. I guess this problem
would be more likely to occur in high-load environments.
This change detaches the pthread after pthread_setaffinity is called.
[Feature #19965]
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/raddrinfo.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 3a60330cce..f5c8ca592a 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -481,13 +481,13 @@ start: return EAI_AGAIN; } - pthread_detach(th); #if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU) cpu_set_t tmp_cpu_set; CPU_ZERO(&tmp_cpu_set); CPU_SET(sched_getcpu(), &tmp_cpu_set); pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set); #endif + pthread_detach(th); rb_thread_call_without_gvl2(wait_getaddrinfo, arg, cancel_getaddrinfo, arg); @@ -700,13 +700,13 @@ start: return EAI_AGAIN; } - pthread_detach(th); #if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU) cpu_set_t tmp_cpu_set; CPU_ZERO(&tmp_cpu_set); CPU_SET(sched_getcpu(), &tmp_cpu_set); pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set); #endif + pthread_detach(th); rb_thread_call_without_gvl2(wait_getnameinfo, arg, cancel_getnameinfo, arg); |