Skip to content

Commit c933e58

Browse files
committed
Quick fix
1 parent d2b891a commit c933e58

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Firestore/core/src/firebase/firestore/remote/grpc_stream.cc

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,8 @@ void GrpcStream::Shutdown() {
187187
// called, otherwise the real failure cause will be overwritten by status
188188
// "canceled".)
189189
context_->TryCancel();
190-
// All completions issued by this call must be taken off the queue before
191-
// finish operation can be enqueued.
192-
FastFinishCompletionsBlocking();
193-
194-
GrpcCompletion* completion = NewCompletion(Type::Finish, {});
195-
call_->Finish(completion->status(), completion);
196-
190+
FinishCall({});
191+
// Wait until "finish" is off the queue.
197192
FastFinishCompletionsBlocking();
198193
}
199194

@@ -204,6 +199,14 @@ void GrpcStream::MaybeUnregister() {
204199
}
205200
}
206201

202+
void GrpcStream::FinishCall(const OnSuccess& callback) {
203+
// All completions issued by this call must be taken off the queue before
204+
// finish operation can be enqueued.
205+
FastFinishCompletionsBlocking();
206+
GrpcCompletion* completion = NewCompletion(Type::Finish, callback);
207+
call_->Finish(completion->status(), completion);
208+
}
209+
207210
void GrpcStream::FastFinishCompletionsBlocking() {
208211
// TODO(varconst): reset buffered_writer_? Should not be necessary, because it
209212
// should never be called again after a call to Finish.
@@ -274,20 +277,10 @@ void GrpcStream::OnWrite() {
274277
}
275278

276279
void GrpcStream::OnOperationFailed() {
277-
if (!completions_.empty()) {
278-
// It is only valid to finish a call once all other completions issued from
279-
// this call have been taken off the queue, so wait until the queue is
280-
// drained. Once a single operation has failed, the rest are guaranteed to
281-
// fail, too.
282-
return;
283-
}
284-
285-
GrpcCompletion* completion =
286-
NewCompletion(Type::Finish, [this](const GrpcCompletion* completion) {
280+
FinishCall([this](const GrpcCompletion* completion) {
287281
Status status = ConvertStatus(*completion->status());
288282
FinishAndNotify(status);
289283
});
290-
call_->Finish(completion->status(), completion);
291284
}
292285

293286
void GrpcStream::RemoveCompletion(const GrpcCompletion* to_remove) {
@@ -304,7 +297,9 @@ GrpcCompletion* GrpcStream::NewCompletion(Type tag,
304297
RemoveCompletion(completion);
305298

306299
if (ok) {
307-
on_success(completion);
300+
if (on_success) {
301+
on_success(completion);
302+
}
308303
} else {
309304
// Use the same error-handling for all operations; all errors are
310305
// unrecoverable.

Firestore/core/src/firebase/firestore/remote/grpc_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class GrpcStream : public GrpcCall {
196196
using OnSuccess = std::function<void(const GrpcCompletion*)>;
197197
GrpcCompletion* NewCompletion(GrpcCompletion::Type type,
198198
const OnSuccess& callback);
199+
void FinishCall(const OnSuccess& callback);
199200

200201
// Blocks until all the completions issued by this stream come out from the
201202
// gRPC completion queue. Once they do, it is safe to delete this `GrpcStream`

0 commit comments

Comments
 (0)