Skip to content

Fix User.stop() crash when greenlet hasn't started yet - #3506

Merged
cyberw merged 2 commits into
locustio:masterfrom
reachsridhard:fix/user-stop-crash-on-none-state
Sep 6, 2026
Merged

Fix User.stop() crash when greenlet hasn't started yet#3506
cyberw merged 2 commits into
locustio:masterfrom
reachsridhard:fix/user-stop-crash-on-none-state

Conversation

@reachsridhard

Copy link
Copy Markdown
Contributor

Fix User.stop() for users whose greenlet has not started

Summary

Fixes User.stop(force=False) raising an exception when a user's greenlet has been spawned but has not started running yet (_state is None).

This can occur during spawning when a test is stopped with a non-zero --stop-timeout.

Fix

Treat _state is None the same as LOCUST_STATE_WAITING and kill the greenlet immediately:

- if force or self._state == LOCUST_STATE_WAITING:
+ if force or self._state in (None, LOCUST_STATE_WAITING):
      self._group.killone(self._greenlet)
      return True

A user in this state has not started running, so there is no task or on_start hook to wait for.

Testing

Added test_stop_user_before_greenlet_starts to reproduce the issue.

@cyberw
cyberw merged commit 5b98622 into locustio:master Sep 6, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants