diff --git a/src/ckpool.c b/src/ckpool.c index d6091ff8..004a09a3 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -526,6 +526,8 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch else ret = true; shutdown(sockd, SHUT_WR); + if (!wait_close(sockd, 5)) + LOGWARNING("send_proc did not close from %s %s:%d", file, func, line); out: if (unlikely(!ret)) { LOGERR("Failure in send_proc from %s %s:%d", file, func, line); diff --git a/src/libckpool.c b/src/libckpool.c index 19fe19ed..cae50bda 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -910,6 +910,20 @@ out: return sockd; } +/* Wait till a socket has been closed at the other end */ +int wait_close(int sockd, int timeout) +{ + struct pollfd sfd; + + if (unlikely(sockd < 0)) + return -1; + sfd.fd = sockd; + sfd.events = POLLHUP; + sfd.revents = 0; + timeout *= 1000; + return poll(&sfd, 1, timeout); +} + /* Emulate a select read wait for high fds that select doesn't support */ int wait_read_select(int sockd, int timeout) { diff --git a/src/libckpool.h b/src/libckpool.h index e21acc96..79f0f8fd 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -493,6 +493,7 @@ int _open_unix_server(const char *server_path, const char *file, const char *fun #define open_unix_server(server_path) _open_unix_server(server_path, __FILE__, __func__, __LINE__) int _open_unix_client(const char *server_path, const char *file, const char *func, const int line); #define open_unix_client(server_path) _open_unix_client(server_path, __FILE__, __func__, __LINE__) +int wait_close(int sockd, int timeout); int wait_read_select(int sockd, int timeout); int read_length(int sockd, void *buf, int len); char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line);