mirror of
git://sourceware.org/git/glibc.git
synced 2024-11-21 01:12:26 +08:00
__check_pf: Add a cancellation cleanup handler [BZ #20975]
There are reports for hang in __check_pf: https://github.com/JoeDog/siege/issues/4 It is reproducible only under specific configurations: 1. Large number of cores (>= 64) and large number of threads (> 3X of the number of cores) with long lived socket connection. 2. Low power (frequency) mode. 3. Power management is enabled. While holding lock, __check_pf calls make_request which calls __sendto and __recvmsg. Since __sendto and __recvmsg are cancellation points, lock held by __check_pf won't be released and can cause deadlock when thread cancellation happens in __sendto or __recvmsg. Add a cancellation cleanup handler for __check_pf to unlock the lock when cancelled by another thread. This fixes BZ #20975 and the siege hang issue.
This commit is contained in:
parent
a225cb3ee9
commit
a443bd3fb2
@ -529,6 +529,8 @@ sysdep_headers += \
|
||||
sysdep_routines += \
|
||||
netlink_assert_response \
|
||||
# sysdep_routines
|
||||
|
||||
CFLAGS-check_pf.c += -fexceptions
|
||||
endif
|
||||
|
||||
# Don't compile the ctype glue code, since there is no old non-GNU C library.
|
||||
|
@ -292,6 +292,14 @@ make_request (int fd, pid_t pid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
static void
|
||||
cancel_handler (void *arg __attribute__((unused)))
|
||||
{
|
||||
/* Release the lock. */
|
||||
__libc_lock_unlock (lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
attribute_hidden
|
||||
@ -304,6 +312,10 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
|
||||
struct cached_data *olddata = NULL;
|
||||
struct cached_data *data = NULL;
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
/* Make sure that lock is released when the thread is cancelled. */
|
||||
__libc_cleanup_push (cancel_handler, NULL);
|
||||
#endif
|
||||
__libc_lock_lock (lock);
|
||||
|
||||
if (cache_valid_p ())
|
||||
@ -338,6 +350,9 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EXCEPTIONS
|
||||
__libc_cleanup_pop (0);
|
||||
#endif
|
||||
__libc_lock_unlock (lock);
|
||||
|
||||
if (data != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user