From 726428a2c5e42e426720dde8a695fa829670b4e4 Mon Sep 17 00:00:00 2001 From: alesapin Date: Tue, 21 Aug 2018 18:24:20 +0300 Subject: [PATCH 1/3] Add timeout to socket --- dbms/src/Common/TaskStatsInfoGetter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dbms/src/Common/TaskStatsInfoGetter.cpp b/dbms/src/Common/TaskStatsInfoGetter.cpp index 8f4d1c6c4ee..a9e5f6f636a 100644 --- a/dbms/src/Common/TaskStatsInfoGetter.cpp +++ b/dbms/src/Common/TaskStatsInfoGetter.cpp @@ -139,7 +139,13 @@ void TaskStatsInfoGetter::init() if (netlink_socket_fd >= 0) return; + struct timeval tv; + tv.tv_sec = 5; + tv.tv_usec = 0; + netlink_socket_fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + ::setsockopt(netlink_socket_fd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&tv), sizeof(tv)); + if (netlink_socket_fd < 0) throwFromErrno("Can't create PF_NETLINK socket"); From df012657e84ac2083ee118a3a31ace5589204206 Mon Sep 17 00:00:00 2001 From: alesapin Date: Tue, 21 Aug 2018 18:40:19 +0300 Subject: [PATCH 2/3] Change time to 50 mseconds --- dbms/src/Common/TaskStatsInfoGetter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbms/src/Common/TaskStatsInfoGetter.cpp b/dbms/src/Common/TaskStatsInfoGetter.cpp index a9e5f6f636a..3e65e5e0007 100644 --- a/dbms/src/Common/TaskStatsInfoGetter.cpp +++ b/dbms/src/Common/TaskStatsInfoGetter.cpp @@ -140,8 +140,8 @@ void TaskStatsInfoGetter::init() return; struct timeval tv; - tv.tv_sec = 5; - tv.tv_usec = 0; + tv.tv_sec = 0; + tv.tv_usec = 50000; netlink_socket_fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_GENERIC); ::setsockopt(netlink_socket_fd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&tv), sizeof(tv)); From 46f00c37e47320b585e99ddd7404c64a684412d1 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Tue, 21 Aug 2018 19:13:07 +0300 Subject: [PATCH 3/3] Update TaskStatsInfoGetter.cpp --- dbms/src/Common/TaskStatsInfoGetter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbms/src/Common/TaskStatsInfoGetter.cpp b/dbms/src/Common/TaskStatsInfoGetter.cpp index 3e65e5e0007..204b86750b4 100644 --- a/dbms/src/Common/TaskStatsInfoGetter.cpp +++ b/dbms/src/Common/TaskStatsInfoGetter.cpp @@ -144,10 +144,11 @@ void TaskStatsInfoGetter::init() tv.tv_usec = 50000; netlink_socket_fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_GENERIC); - ::setsockopt(netlink_socket_fd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&tv), sizeof(tv)); - if (netlink_socket_fd < 0) throwFromErrno("Can't create PF_NETLINK socket"); + + if (0 != ::setsockopt(netlink_socket_fd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&tv), sizeof(tv))) + throwFromErrno("Can't set timeout on PF_NETLINK socket"); ::sockaddr_nl addr{}; addr.nl_family = AF_NETLINK;