Check for closed StreamController in more places (#623)

This commit is contained in:
Nate Bosch 2023-04-21 12:34:00 -07:00 committed by GitHub
parent a1a8e92e38
commit 7be6275f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -209,9 +209,7 @@ class ClientCall<Q, R> implements Response {
void _terminateWithError(GrpcError error) {
_finishTimelineWithError(error, _requestTimeline);
if (!_responses.isClosed) {
_responses.addError(error);
}
_responses.addErrorIfNotClosed(error);
_safeTerminate();
}
@ -300,7 +298,7 @@ class ClientCall<Q, R> implements Response {
void _onTimedOut() {
final error = GrpcError.deadlineExceeded('Deadline exceeded');
_finishTimelineWithError(error, _requestTimeline);
_responses.addError(error);
_responses.addErrorIfNotClosed(error);
_safeTerminate();
}
@ -329,7 +327,7 @@ class ClientCall<Q, R> implements Response {
/// Emit an error response to the user, and tear down this call.
void _responseError(GrpcError error, [StackTrace? stackTrace]) {
_finishTimelineWithError(error, _responseTimeline);
_responses.addError(error, stackTrace);
_responses.addErrorIfNotClosed(error);
_timeoutTimer?.cancel();
_requestSubscription?.cancel();
_responseSubscription!.cancel();
@ -444,7 +442,7 @@ class ClientCall<Q, R> implements Response {
}
_finishTimelineWithError(error, _requestTimeline);
_responses.addError(error, stackTrace);
_responses.addErrorIfNotClosed(error);
_timeoutTimer?.cancel();
_responses.close();
_requestSubscription?.cancel();
@ -494,3 +492,11 @@ class ClientCall<Q, R> implements Response {
} catch (_) {}
}
}
extension<T> on StreamController<T> {
void addErrorIfNotClosed(Object error, [StackTrace? stackTrace]) {
if (!isClosed) {
addError(error, stackTrace);
}
}
}