Skip to content

close() closes the core before async hooks finish, and drain() can wait on its own task #88

Closed

Description

@fctl-sh

Priority: medium.

  • Async hooks cannot use the client during close() (client.py, close(): it sets the closed flag and closes the core before events.drain()). An async operation.failed hook that awaits and then writes an audit item gets ShutdownError (reported as hook.failed), and the item is never written, although the docs say "the client waits for them at close()".
  • events.drain() gathers its own task and tasks of other loops (events.py): an async hook that calls await client.close() never finishes (at shutdown asyncio.run raises RecursionError while cancelling it), and with a client used from two event loops (test_clients_work_across_event_loops), a hook still pending on the closed second loop makes close() raise ValueError: The future belongs to a different loop, after the core is already closed.

Fix: drain the hook tasks of the current loop, except the calling task, before closing the core.

Found in a review of the library for bugs (fctl session); the fixes that fit in its ten pull requests are #61 to #65, #67 to #70 and #72.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. added a commit that references this issue on Oct 31, 2026
    779546c
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions