Skip to content

Commit 31afcb9

Browse files
committed
Bug#29431134: MASTER : HANG IN SESSION CREATION TN INVALID HOST ON WINDOWS
Make sure that negative timeout values are not passed to the poll() OS call which would then be casted to unsigned integer and become very large timeouts.
1 parent 354a762 commit 31afcb9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cdk/foundation/socket_detail.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,14 @@ Socket connect(const char *host_name, unsigned short port,
607607
if (connect_result == SOCKET_ERROR && errno == EINPROGRESS)
608608
#endif
609609
{
610-
int select_result = poll_one(socket, POLL_MODE_CONNECT,true,
611-
(uint64_t)duration_cast<microseconds>(
612-
deadline - system_clock::now()).count());
610+
auto timeout = duration_cast<microseconds>(
611+
deadline - system_clock::now()
612+
).count();
613+
614+
int select_result = poll_one(
615+
socket, POLL_MODE_CONNECT, true,
616+
timeout_usec > 0 && timeout > 0 ? timeout : 0
617+
);
613618

614619
if (select_result == 0 && (timeout_usec > 0) &&
615620
(std::chrono::system_clock::now() >= deadline))
@@ -790,13 +795,8 @@ DIAGNOSTIC_PUSH_CDK
790795
DIAGNOSTIC_POP_CDK
791796

792797
//milliseconds
793-
int timeout = -1;
794-
795-
if (wait && timeout_usec > 0)
796-
{
797-
// If timeout is specified we will use it
798-
timeout = static_cast<int>(timeout_usec / 1000);
799-
}
798+
int timeout =
799+
!wait ? 0 : timeout_usec > 0 ? static_cast<int>(timeout_usec / 1000) : -1;
800800

801801
#ifdef _WIN32
802802
int result = ::WSAPoll(&fds, 1, timeout);

0 commit comments

Comments
 (0)