Skip to content

Commit 50d4701

Browse files
Fix
1 parent 295d29b commit 50d4701

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/firestore/src/remote/remote_store.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,25 @@ export class RemoteStore implements TargetMetadataProvider {
719719
'Write stream was stopped gracefully while still needed.'
720720
);
721721
}
722-
// An error that occurs after the write handshake completes is an indication
723-
// that the write operation itself failed.
724-
if (error && this.writeStream.handshakeComplete) {
725-
// This error affects the actual write.
726-
await this.handleWriteError(error!);
727-
} else if (error) {
728-
// If there was an error before the handshake has finished, it's
729-
// possible that the server is unable to process the stream token
730-
// we're sending. (Perhaps it's too old?)
731-
await this.handleHandshakeError(error!);
732-
}
733722

734-
// The write stream might have been started by refilling the write
735-
// pipeline for failed writes
736-
if (this.shouldStartWriteStream()) {
737-
this.startWriteStream();
723+
// If the write stream closed due to an error, invoke the error callbacks if
724+
// there are pending writes.
725+
if (error && this.writePipeline.length > 0) {
726+
if (this.writeStream.handshakeComplete) {
727+
// This error affects the actual write.
728+
await this.handleWriteError(error!);
729+
} else {
730+
// If there was an error before the handshake has finished, it's
731+
// possible that the server is unable to process the stream token
732+
// we're sending. (Perhaps it's too old?)
733+
await this.handleHandshakeError(error!);
734+
}
735+
736+
// The write stream might have been started by refilling the write
737+
// pipeline for failed writes
738+
if (this.shouldStartWriteStream()) {
739+
this.startWriteStream();
740+
}
738741
}
739742
// No pending writes, nothing to do
740743
}

0 commit comments

Comments
 (0)