Commit 58d4cbfe authored by Kirill Smelkov's avatar Kirill Smelkov

context: Fix deadlock when new context is created from already-canceled parent

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
parent d0688e21
Pipeline #18679 passed with stage
in 0 seconds