Fixed destroy race in NotifiedQueue

This commit is contained in:
Josh Slocum 2022-01-10 10:30:14 -06:00
parent ce67e2e583
commit 95e2d0993f
1 changed files with 6 additions and 5 deletions

View File

@ -1008,17 +1008,18 @@ struct NotifiedQueue : private SingleCallback<T>, FastAllocated<NotifiedQueue<T>
ASSERT(this->error.code() != error_code_success);
this->error = err;
if (shouldFireImmediately()) {
SingleCallback<T>::next->error(err);
}
// end_of_stream error is "expected", don't terminate reading stream early for this
// weird destruction issue with sending broken_promise, so just ignore it. Stream is dead anyway. TODO better
// fix?
// onError must be triggered before callback, otherwise callback could cause delPromiseRef/delFutureRef. This
// could destroy *this* in the callback, causing onError to be referenced after this object is destroyed.
if (err.code() != error_code_end_of_stream && err.code() != error_code_broken_promise && onError.isValid()) {
ASSERT(onError.canBeSet());
onError.sendError(err);
}
if (shouldFireImmediately()) {
SingleCallback<T>::next->error(err);
}
}
void addPromiseRef() { promises++; }