MEDIUM: threads/server: Use the server lock to protect health check and cli concurrency
diff --git a/src/stats.c b/src/stats.c
index e026f36..f688319 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -2764,6 +2764,7 @@
 					reprocess = 1;
 				}
 				else if ((sv = findserver(px, value)) != NULL) {
+					SPIN_LOCK(SERVER_LOCK, &sv->lock);
 					switch (action) {
 					case ST_ADM_ACTION_DISABLE:
 						if (!(sv->cur_admin & SRV_ADMF_FMAINT)) {
@@ -2880,17 +2881,16 @@
 						if (px->state != PR_STSTOPPED) {
 							struct stream *sess, *sess_bck;
 
-							SPIN_LOCK(SERVER_LOCK, &sv->lock);
 							list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
 								if (sess->srv_conn == sv)
 									stream_shutdown(sess, SF_ERR_KILLED);
-							SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
 
 							altered_servers++;
 							total_servers++;
 						}
 						break;
 					}
+					SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
 				} else {
 					/* the server name is unknown or ambiguous (duplicate names) */
 					total_servers++;