Skip to content

_IocpProactor._poll might need to account for _unregistered #90

Closed

Description

@stat1c-void

Hi!

I've been hitting a problem on Windows with IocpProactor not closing.
Firstly, it seems to be solved in recent commits - when using master code the problem does not seem to appear anymore, thanks! It seems additional locking has solved it (#87).

I've asked my debugging question and described details on python forums: https://discuss.python.org/t/asyncio-iocpproactor-does-not-close/35206
Mind you, all my thoughts at the end seem to be completely wrong.

But I wonder if overridden _IocpProactor._poll is missing this code from upstream _poll?

        # Remove unregistered futures
        for ov in self._unregistered:
            self._cache.pop(ov.address, None)
        self._unregistered.clear()

https://github.com/python/cpython/blob/43a6e4fa4934fcc0cbd83f7f3dc1b23a5f79f24b/Lib/asyncio/windows_events.py#L825-L828

Because after some more debugging I expected that's the problem - items from _cache do not get evicted, they are unregistered, but hang in _cache.
Unless _unregister does not get called at all with the overridden proactor? But I think it can be called from run_forever:
https://github.com/python/cpython/blob/43a6e4fa4934fcc0cbd83f7f3dc1b23a5f79f24b/Lib/asyncio/windows_events.py#L332-L334

Activity

  1. hosaka commented on Oct 4, 2023

    @hosaka
    Collaborator

    Hi, thanks for bringing this up.

    Reading the comment for cpython run_forever, it does suggest that the IocpProactor.close will wait forever, qasync also calls this method. So without popping futures from cache (even though they are marked as unregistered), the while self._cache in the IocpProactor.close will never close itself.

    I this this should be added to the _poll override.

  2. stat1c-void commented on Oct 4, 2023

    @stat1c-void
    Author

    Alright, should I do a PR?

  3. hosaka commented on Oct 6, 2023

    @hosaka
    Collaborator

    I'll submit it later on today, cheers

  4. stat1c-void commented on Oct 6, 2023

    @stat1c-void
    Author

    Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions