Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot stop locust in case of exceptions in on_stop() #2401

Closed
Zazhka opened this issue Sep 21, 2023 · 3 comments
Closed

Cannot stop locust in case of exceptions in on_stop() #2401

Zazhka opened this issue Sep 21, 2023 · 3 comments
Labels

Comments

@Zazhka
Copy link

Zazhka commented Sep 21, 2023

Describe the bug

Locust execution cannot be stopped by the UI if any exception occurs during the cleanup phase in on_stop() .

Expected behavior

Execution of the task set should be stopped regardless of any exceptions in the on_stop methods.

Actual behavior

In case of any exceptions in the on_stop method, the following error appears in the logs:

Traceback (most recent call last):
  File "/.venv/lib/python3.11/site-packages/locust/user/task.py", line 353, in run
    self.wait()
  File "/.venv/lib/python3.11/site-packages/locust/user/task.py", line 445, in wait
    self._sleep(self.wait_time())
  File "/.venv/lib/python3.11/site-packages/locust/user/task.py", line 451, in _sleep
    gevent.sleep(seconds)
  File "/.venv/lib/python3.11/site-packages/gevent/hub.py", line 166, in sleep
    hub.wait(t)
  File "src/gevent/_hub_primitives.py", line 46, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait
  File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait
  File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
greenlet.GreenletExit

After that users will continue to send requests. They cannot be stopped through UI with Stop button, setting users to 0, etc. Then they only can be stopped by killing the locust instances. Test execution does not stop in headless mode as well.

Steps to reproduce

from locust import HttpUser, task, between, TaskSet

class LocustUser(HttpUser):
    wait_time = between(1, 5)

    @task
    class MyTaskSet(TaskSet):
        @task
        def hello_world(self):
            self.client.get('/hello')

        def on_stop(self):
            assert True == False 

Environment

  • OS: MacOS 13.5.2
  • Python version: 3.11.5
  • Locust version: 2.16.1
  • Locust command line that you ran: locust -f locust_file.py -u 2 --host http://localhost:8089
  • Locust file contents (anonymized if necessary): example above
@Zazhka Zazhka added the bug label Sep 21, 2023
@cyberw
Copy link
Collaborator

cyberw commented Sep 21, 2023

I made a fix, that should sort this out, but I had some issues constructing a test case. Can you try it out and see if it works?

@cyberw cyberw closed this as completed in df3d0d7 Sep 21, 2023
@cyberw
Copy link
Collaborator

cyberw commented Sep 21, 2023

You can install the very latest version using pip install -U --pre locust (in a couple of minutes)

@Zazhka
Copy link
Author

Zazhka commented Sep 21, 2023

Looks good now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants