Skip to content

Commit 0af464c

Browse files
author
Dmitry Antipov
authored
posix: fix thread leak (#2851)
When restarting POSIX health check thread, terminate the previous instance with 'gf_thread_cleanup_xint()' instead of 'pthread_cancel()' and so avoid thread leak due to missing call to 'pthread_join()'. Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com> Updates: #1000
1 parent 1f39dc3 commit 0af464c

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

xlators/storage/posix/src/posix-helpers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,10 +2227,10 @@ posix_spawn_health_check_thread(xlator_t *xl)
22272227
{
22282228
/* cancel the running thread */
22292229
if (priv->health_check_active == _gf_true) {
2230-
ret = pthread_cancel(priv->health_check);
2230+
ret = gf_thread_cleanup_xint(priv->health_check);
22312231
if (ret != 0) {
2232-
gf_msg(xl->name, GF_LOG_ERROR, ret, P_MSG_PTHREAD_CANCEL_FAILED,
2233-
"Failed to send cancellation to health-check thread");
2232+
gf_msg(xl->name, GF_LOG_ERROR, ret, P_MSG_HEALTHCHECK_FAILED,
2233+
"failed to terminate health-check thread");
22342234
ret = -1;
22352235
goto unlock;
22362236
}

xlators/storage/posix/src/posix-messages.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ GLFS_MSGID(POSIX, P_MSG_XATTR_FAILED, P_MSG_NULL_GFID, P_MSG_FCNTL_FAILED,
6969
P_MSG_FETCHMDATA_FAILED, P_MSG_GETMDATA_FAILED,
7070
P_MSG_SETMDATA_FAILED, P_MSG_FRESHFILE, P_MSG_MUTEX_FAILED,
7171
P_MSG_COPY_FILE_RANGE_FAILED, P_MSG_TIMER_DELETE_FAILED, P_MSG_NOMEM,
72-
P_MSG_PSTAT_FAILED, P_MSG_FDSTAT_FAILED, P_MSG_POSIX_IO_URING,
73-
P_MSG_PTHREAD_CANCEL_FAILED);
72+
P_MSG_PSTAT_FAILED, P_MSG_FDSTAT_FAILED, P_MSG_POSIX_IO_URING);
7473

7574
#endif /* !_GLUSTERD_MESSAGES_H_ */

0 commit comments

Comments
 (0)