Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry streaming methods if initial write errored #897

Merged
merged 2 commits into from Jan 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 19 additions & 15 deletions dev/src/index.ts
Expand Up @@ -1148,8 +1148,6 @@ export class Firestore {
}
}

backendStream.on('data', () => streamReady());

function streamEnded() {
logger(
'Firestore._initializeStream',
Expand All @@ -1161,11 +1159,7 @@ export class Firestore {
lifetime.resolve();
}

backendStream.on('end', () => streamEnded());
backendStream.on('close', () => streamEnded());
backendStream.on('finish', () => streamEnded());

backendStream.on('error', err => {
function streamFailed(err: Error) {
if (!streamInitialized) {
// If we receive an error before we were able to receive any data,
// reject this stream.
Expand All @@ -1191,7 +1185,13 @@ export class Firestore {
resultStream.emit('error', err);
});
}
});
}

backendStream.on('data', () => streamReady());
backendStream.on('error', err => streamFailed(err));
backendStream.on('end', () => streamEnded());
backendStream.on('close', () => streamEnded());
backendStream.on('finish', () => streamEnded());

backendStream.pipe(resultStream);

Expand All @@ -1202,13 +1202,17 @@ export class Firestore {
'Sending request: %j',
request
);
backendStream.write(request, 'utf-8', () => {
logger(
'Firestore._initializeStream',
requestTag,
'Marking stream as healthy'
);
streamReady();
backendStream.write(request, 'utf-8', err => {
if (err) {
streamFailed(err);
} else {
logger(
'Firestore._initializeStream',
requestTag,
'Marking stream as healthy'
);
streamReady();
}
});
}
});
Expand Down