Skip to content

Commit 7ccf870

Browse files
rluboskartben
authored andcommitted
net: coap_client: Stop all socket activities when cancelling requests
Calling coap_client_cancel_requests() clears the internal request context only for active requests (i. e. not replied yet). However, if there are any pending request context monitoring ACK duplicates, those would still make the corresponding client socket being monitored by poll(). In result, when application closes the socket, the polling thread will throw POLLNVAL error for the socket. Fix this, by resetting all request contexts unconditionally. The request callback will only be called for the active requests. Signed-off-by: Robert Lubos <[email protected]>
1 parent 3f81e81 commit 7ccf870

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/zephyr/net/coap_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr
157157
*
158158
* This is intended for canceling long-running requests (e.g. GETs with the OBSERVE option set)
159159
* which has gone stale for some reason.
160+
* The function should also be called before the corresponding client socket is closed,
161+
* to prevent the socket from being monitored by the internal polling thread.
160162
*
161163
* @param client Client instance.
162164
*/

subsys/net/lib/coap/coap_client.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,14 +1013,12 @@ static void cancel_requests_with(struct coap_client *client, int error)
10131013
* request was cancelled anyway.
10141014
*/
10151015
report_callback_error(&client->requests[i], error);
1016-
release_internal_request(&client->requests[i]);
10171016
}
1018-
/* If our socket has failed, clear all requests, even completed ones,
1019-
* so that our handle_poll() does not poll() anymore for this socket.
1017+
1018+
/* Clear all requests, even completed ones, so that our
1019+
* handle_poll() does not poll() anymore for this socket.
10201020
*/
1021-
if (error == -EIO) {
1022-
reset_internal_request(&client->requests[i]);
1023-
}
1021+
reset_internal_request(&client->requests[i]);
10241022
}
10251023
k_mutex_unlock(&client->lock);
10261024

0 commit comments

Comments
 (0)