• Kirill Smelkov's avatar
    context: Fix deadlock when new context is created from already-canceled parent · 58d4cbfe
    Kirill Smelkov authored
    When _BaseCtx is setting up cancel propagation it locks a parent,
    checks for parent.err != nil, and, if it is, calls
    ctx._cancel(parent.err) _with_ _holding_ parent.mu. Since _cancel
    internally also goes through parents and locks them, this was deadlocking
    on the second call to parent.mu.lock().
    
    -> Fix it by calling ctx._cancel(err) in the constructor outside of
    parent lock.
    
    The bug was there from the beginning - from e9567c7b (context: New
    package that mirrors Go's context).
    
    /trusted-by @jerome
    /reviewed-on nexedi/pygolang!16
    58d4cbfe
context_test.py 10.8 KB