Skip to content

fix(utilities): concurrent first access to lazy protocol exports deadlocks the import system #2771

Closed

Description

@JarryShaw

Describe the bug
Since #2757, threads that reach different lazy exports of pcapkit.protocols at the same time on a cold import deadlock the import system: _DeadlockError: deadlock detected by _ModuleLock('pcapkit.protocols.link.arp.data'). 1.5.1 imported these eagerly, so this is a regression on main. Reaching a single name from many threads does not trigger it.

Reproduction

import threading, pcapkit.protocols as P
names = P.__all__[:16]; b = threading.Barrier(len(names)); errs = []
def go(n):
    b.wait()
    try: getattr(P, n)
    except BaseException as e: errs.append(repr(e))
ts = [threading.Thread(target=go, args=(n,)) for n in names]; [t.start() for t in ts]; [t.join() for t in ts]
print(errs[:1])   # _DeadlockError ... in 19 of 20 fresh processes at 8c30106c7

Expected behavior
Concurrent first access resolves every name, as the eager 1.5.1 imports did.

Additional context
The threads take per-module import locks in different orders, and the protocol/schema/data modules import each other. A likely fix is to serialise first resolution in the shared pcapkit.utilities.importlib.lazy_exports hook, rather than per package. The #2757 thread test only raced on the registry.

Activity

  1. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 4, 2026
  2. added this to the PyPCAPKit v1.6 milestone on Nov 4, 2026
  3. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 4, 2026
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

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions