From: Willy Tarreau Date: Tue, 18 Mar 2025 10:38:56 +0000 (+0100) Subject: CLEANUP: server: make it clear that srv_check_for_deletion() is thread-safe X-Git-Tag: v3.2-dev8~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aad8e74cb9c382c5a0ab1a53aff0e38b06ce6806;p=thirdparty%2Fhaproxy.git CLEANUP: server: make it clear that srv_check_for_deletion() is thread-safe This function was marked as requiring thread isolation because its code was extracted from cli_parse_delete_server() and was running under isolation. But upon closer inspection, and using atomic loads to check a few counters, it is actually safe to run without isolation, so let's reflect that in its description. However, it remains true that cli_parse_delete_server() continues to call it under isolation. --- diff --git a/src/server.c b/src/server.c index 9fa7dfb33..6d9e696ca 100644 --- a/src/server.c +++ b/src/server.c @@ -6044,11 +6044,13 @@ out: } /* Check if the server / exists and is ready for being deleted. - * Both and must be valid strings. This must be called under - * thread isolation. If pb/ps are not null, upon success, the pointer to - * the backend and server respectively will be put there. If pm is not null, - * a pointer to an error/success message is returned there (possibly NULL if - * nothing to say). Returned values: + * This means that the server is in maintenance with no streams attached to it, + * no queue and no used idle conns. This is not supposed to change during all + * the maintenance phase (except for force-persist etc, which are not covered). + * Both and must be valid strings. If pb/ps are not null, + * upon success, the pointer to the backend and server respectively will be put + * there. If pm is not null, a pointer to an error/success message is returned + * there (possibly NULL if nothing to say). Returned values: * >0 if OK * 0 if not yet (should wait if it can) * <0 if not possible @@ -6091,8 +6093,8 @@ int srv_check_for_deletion(const char *bename, const char *svname, struct proxy ret = 0; /* Ensure that there is no active/pending connection on the server. */ - if (srv->curr_used_conns || - srv->queueslength || srv_has_streams(srv)) { + if (_HA_ATOMIC_LOAD(&srv->curr_used_conns) || + _HA_ATOMIC_LOAD(&srv->queueslength) || srv_has_streams(srv)) { msg = "Server still has connections attached to it, cannot remove it."; goto leave; }