Skip to content

IOLoop._instance is never set, causing hanging callbacks on multi-threaded tests #27

@wouterdb

Description

@wouterdb

I noticed a subtle problem when using IOLoop.current(instance=True) in multi-threaded applications when using pytest-tornado:

If tornado starts the first IOLoop (on the main thread) it sets IOLoop._instance to point to this IOLoop
However, the fixture never sets this field.

When calling IOLoop.current(instance=True) on any thread except for the thread in which the pytest-tornado ioloop fixture is executed, it will not find a current IOLoop for that thread and fall back to the global IOLoop._instance . If this field is absent, IOLoop assumes this is the first attempt to get an IOLoop and create a new IOLoop and set it as IOLoop._instance.

As such, all calls to IOLoop.current(instance=True) from other threads will get this IOLoop instance, which has not been started. All calls scheduled on that IOLoop will hang, causing tests to timeout.

Setting IOLoop._instance before the test and removing it afterwards resolves the issue.

(I hope my description is clear).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions