Good catch. A solution is to have `eventQueue` peek instead of take in https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/scheduler/LiveListenerBus.scala#L43, such that we remove the event from the queue only after all listeners have finished processing it.

Many other places have long been relying on `waitUntilEmpty` even before this PR. It makes me wonder how likely this race condition actually causes a test failure...