/swarm accepts negative user_count and reports success
Author: suraj-selfCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbug
Prerequisites
- I am using the latest version of Locust
- I am reporting a bug, not asking a question
Description
Steps to reproduce
Start Locust:
locust -f locustfile.pyThen send a /swarm request with a negative user_count:
curl -X POST http://127.0.0.1:8089/swarm \
-d "user_count=-10" \
-d "spawn_rate=1"Actual behavior
The endpoint returns HTTP 200 with:
{
"host": null,
"message": "Swarming started",
"success": true
}
However, the runner then fails asynchronously with:
(locust) ss@ss-Predator-PH315-53:~/locust$ locust -f locustfile.py
[2026-09-29 23:34:31,039] ss-Predator-PH315-53/INFO/locust.main: Starting Locust 0.1.dev6564
[2026-09-29 23:34:31,039] ss-Predator-PH315-53/INFO/locust.main: Starting web interface at http://0.0.0.0:8089, press enter to open your default browser.
[2026-09-29 23:34:32,760] ss-Predator-PH315-53/INFO/locust.runners: Ramping to -10 users at a rate of 1.00 per second
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 912, in gevent._gevent_cgreenlet.Greenlet.run
File "/home/ss/locust/locust/runners.py", line 559, in <lambda>
lambda: self._start(user_count, spawn_rate, wait=wait, user_classes=user_classes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ss/locust/locust/runners.py", line 505, in _start
self._users_dispatcher.new_dispatch(user_count, spawn_rate, user_classes)
File "/home/ss/locust/locust/dispatch.py", line 196, in new_dispatch
raise ValueError(f"target_user_count must be >= 0, got {target_user_count}")
ValueError: target_user_count must be >= 0, got -10
2026-09-29T18:04:32Z <Greenlet at 0x7306338e6520: <lambda>> failed with ValueError
[2026-09-29 23:34:32,762] ss-Predator-PH315-53/CRITICAL/locust.runners: Unhandled exception in greenlet: <Greenlet at 0x7306338e6520: <lambda>>
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 912, in gevent._gevent_cgreenlet.Greenlet.run
File "/home/ss/locust/locust/runners.py", line 559, in <lambda>
lambda: self._start(user_count, spawn_rate, wait=wait, user_classes=user_classes)
^^^^^^^^^^^^^^^^^
File "/home/ss/locust/locust/runners.py", line 505, in _start
self._users_dispatcher.new_dispatch(user_count, spawn_rate, user_classes)
^^^^^^^^^^^^^^^^^
File "/home/ss/locust/locust/dispatch.py", line 196, in new_dispatch
raise ValueError(f"target_user_count must be >= 0, got {target_user_count}")
^^^^^^^^^^^^^^^^^
ValueError: target_user_count must be >= 0, got -10The test does not start and the runner remains at 0 users.
Expected behavior
/swarm should validate user_count before starting the runner and return a validation error with success: false for a negative value.
Additional information
- Non-numeric
user_countvalues are already handled correctly. - This issue is specifically about numeric negative values such as
-10.
Command line
locust -f locustfile.py
Locustfile contents
from locust import User, task
class DummyUser(User):
@task
def my_task(self):
passPython version
Python 3.11.0rc1
Locust version
2.46.6
Operating system
Ubuntu 22.04.5 LTS
Source: locustio/locust