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

WorkerRunner spawns heartbeat before setting worker_state #1500

Closed
Bubba74 opened this issue Aug 3, 2020 · 1 comment
Closed

WorkerRunner spawns heartbeat before setting worker_state #1500

Bubba74 opened this issue Aug 3, 2020 · 1 comment
Labels

Comments

@Bubba74
Copy link

Bubba74 commented Aug 3, 2020

Describe the bug

The WorkerRunner.heartbeat() method fails with
Exception: WorkerRunner object does not have member 'worker_state'

Looking at the WorkerRunner class:

locust/locust/runners.py

Lines 612 to 615 in f5b89d7

self.greenlet.spawn(self.heartbeat).link_exception(greenlet_exception_handler)
self.greenlet.spawn(self.worker).link_exception(greenlet_exception_handler)
self.client.send(Message("client_ready", None, self.client_id))
self.worker_state = STATE_INIT

The heartbeat greenlet is spawned on Line#612, while the WorkerRunner.worker_state is set on Line#615. It might have been a rare case where gevent preempted the current thread in such a short gap. But it definitely happened several times.

Suggested Fix

In the WorkerRunner class:

locust/locust/runners.py

Lines 612 to 615 in f5b89d7

self.greenlet.spawn(self.heartbeat).link_exception(greenlet_exception_handler)
self.greenlet.spawn(self.worker).link_exception(greenlet_exception_handler)
self.client.send(Message("client_ready", None, self.client_id))
self.worker_state = STATE_INIT

Move Line#615 to before Line#612. This guarantees that WorkerRunner.worker_state is set for all calls to heartbeat().

Expected behavior

There should not be an exception.

Actual behavior

The exception occurs.

Steps to reproduce

I'm struggling to reproduce this, but the issue seems easy enough to believe and a possible fix is super easy.

Environment

  • OS:
    Linux 4.4.0-166-generic Execution order? task lifetime? #195-Ubuntu GNU/Linux

  • Python version:
    Python 3.6.9 (2ad108f17bdb, Apr 07 2020, 02:59:05)
    [PyPy 7.3.1 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

  • Locust version:
    locust 1.1.1

  • I can't reproduce this, so I can't provide details here. But I ran a master/1worker setup, both created via library calls, not the command line.

    • Locust command line that you ran:
    • Locust file contents (anonymized if necessary):
@Bubba74 Bubba74 added the bug label Aug 3, 2020
@heyman heyman closed this as completed in 2f8e64e Aug 4, 2020
@heyman
Copy link
Member

heyman commented Aug 4, 2020

Thanks for debugging, reporting and suggesting a fix! Fixed in 2f8e64e.

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