Description
spotted while reviewing #15303
In the Pubsub, we can't hold the qMu
lock while calling Listen
or Unlisten
on the pgListener
, because this lock is also held while delivering notifications. This was the source of a Pubsub deadlock (#11950) that we fixed in #12518. However, that fix leaves us with a new race condition that goes like this:
We have a single subscriber to some event, and they cancel their subscription. Concurrently, we get a new Subscribe call for the same event. Since we don't hold a lock while calling Listen
and Unlisten
, these could happen in any order. If Unlisten
is called last, the new subscriber won't get any events.