Skip to content

Commit b2111a3

Browse files
tomzawadzkitiagolobocastro
authored andcommitted
module/sock: detect POLLHUP in is_connected with buffered data
When the peer closes a connection but unread data remains in the receive buffer, recv(MSG_PEEK) returns > 0 and is_connected() incorrectly reports true. Add poll(POLLHUP) check before recv(MSG_PEEK) to detect peer hangup regardless of buffered data. Fixes spdk#3842 Assisted-by: Cursor Change-Id: Id5a835a6a3d1ceeac08e17ded2d442c300a176d2 Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@nutanix.com> Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/27957 Community-CI: Mellanox Build Bot Tested-by: SPDK Automated Test System <spdkbot@gmail.com> Reviewed-by: Jim Harris <jim.harris@nvidia.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
1 parent cc090cd commit b2111a3

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

module/sock/posix/posix.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,19 @@ posix_sock_is_connected(struct spdk_sock *_sock)
17681768
struct spdk_posix_sock *sock = __posix_sock(_sock);
17691769
uint8_t byte;
17701770
int rc;
1771+
struct pollfd pfd;
17711772

17721773
if (posix_sock_is_connecting(sock)) {
17731774
return false;
17741775
}
17751776

1777+
pfd.fd = sock->fd;
1778+
pfd.events = 0;
1779+
pfd.revents = 0;
1780+
if (poll(&pfd, 1, 0) >= 0 && (pfd.revents & POLLHUP)) {
1781+
return false;
1782+
}
1783+
17761784
rc = recv(sock->fd, &byte, 1, MSG_PEEK);
17771785
if (rc == 0) {
17781786
return false;

module/sock/uring/uring.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,14 @@ uring_sock_is_connected(struct spdk_sock *_sock)
15011501
struct spdk_uring_sock *sock = __uring_sock(_sock);
15021502
uint8_t byte;
15031503
int rc;
1504+
struct pollfd pfd;
1505+
1506+
pfd.fd = sock->fd;
1507+
pfd.events = 0;
1508+
pfd.revents = 0;
1509+
if (poll(&pfd, 1, 0) >= 0 && (pfd.revents & POLLHUP)) {
1510+
return false;
1511+
}
15041512

15051513
rc = recv(sock->fd, &byte, 1, MSG_PEEK | MSG_DONTWAIT);
15061514
if (rc == 0) {

0 commit comments

Comments
 (0)