GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Reset the retry counter to 0 when receiving data (#1604) · googleapis/google-cloud-node@5ab7a37

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/packages/google-gax/gax
    • src/streamingCalls
      • streaming.ts
    • test
      • test-application/src
        • index.ts
      • unit
        • streaming.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/packages/google-gax/gax/src/streamingCalls/streaming.ts‎

Copy file name to clipboardExpand all lines: packages/packages/google-gax/gax/src/streamingCalls/streaming.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
271271
*/
272272
streamHandoffHelper(stream: CancellableStream, retry: RetryOptions): void {
273273
let enteredError = false;
274-
const eventsToForward = ['metadata', 'response', 'status', 'data'];
274+
const eventsToForward = ['metadata', 'response', 'status'];
275275

276276
eventsToForward.forEach(event => {
277277
stream.on(event, this.emit.bind(this, event));
@@ -282,6 +282,11 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
282282
this.streamHandoffErrorHandler(stream, retry, error);
283283
});
284284

285+
stream.on('data', (data: ResponseType) => {
286+
this.retries = 0;
287+
this.emit.bind(this, 'data')(data);
288+
});
289+
285290
stream.on('end', () => {
286291
if (!enteredError) {
287292
enteredError = true;
Collapse file

‎packages/packages/google-gax/gax/test/test-application/src/index.ts‎

Copy file name to clipboardExpand all lines: packages/packages/google-gax/gax/test/test-application/src/index.ts
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ async function testShowcase() {
8080
const restClient = new EchoClient(restClientOpts);
8181
const restClientCompat = new EchoClient(restClientOptsCompat);
8282

83+
await testResetRetriesToZero(grpcSequenceClientWithServerStreamingRetries);
84+
8385
// assuming gRPC server is started locally
8486
await testEcho(grpcClient);
8587
await testEchoError(grpcClient);
@@ -714,6 +716,83 @@ async function testServerStreamingRetrieswithRetryRequestOptions(
714716
});
715717
}
716718

719+
// When the stream recieves data then the retry count should be set to 0
720+
async function testResetRetriesToZero(client: SequenceServiceClient) {
721+
const finalData: string[] = [];
722+
const shouldRetryFn = (error: GoogleError) => {
723+
return [4, 5, 6, 7].includes(error!.code!);
724+
};
725+
const backoffSettings = createBackoffSettings(
726+
10000,
727+
2.5,
728+
1000,
729+
null,
730+
1.5,
731+
3000,
732+
null
733+
);
734+
// intentionally set maxRetries to a value less than
735+
// the number of errors in the sequence
736+
backoffSettings.maxRetries = 2;
737+
const getResumptionRequestFn = (request: RequestType) => {
738+
return request;
739+
};
740+
741+
const retryOptions = new RetryOptions(
742+
[],
743+
backoffSettings,
744+
shouldRetryFn,
745+
getResumptionRequestFn
746+
);
747+
748+
const settings = {
749+
retry: retryOptions,
750+
};
751+
752+
client.initialize();
753+
754+
const request = createStreamingSequenceRequestFactory(
755+
[
756+
Status.DEADLINE_EXCEEDED,
757+
Status.NOT_FOUND,
758+
Status.ALREADY_EXISTS,
759+
Status.PERMISSION_DENIED,
760+
Status.OK,
761+
],
762+
[0.1, 0.1, 0.1, 0.1, 0.1],
763+
[1, 2, 3, 4, 5],
764+
'This is testing the brand new and shiny StreamingSequence server 3'
765+
);
766+
const response = await client.createStreamingSequence(request);
767+
await new Promise<void>((resolve, reject) => {
768+
const sequence = response[0];
769+
770+
const attemptRequest =
771+
new protos.google.showcase.v1beta1.AttemptStreamingSequenceRequest();
772+
attemptRequest.name = sequence.name!;
773+
774+
const attemptStream = client.attemptStreamingSequence(
775+
attemptRequest,
776+
settings
777+
);
778+
attemptStream.on('data', (response: {content: string}) => {
779+
finalData.push(response.content);
780+
});
781+
attemptStream.on('error', error => {
782+
reject(error);
783+
});
784+
attemptStream.on('end', () => {
785+
attemptStream.end();
786+
resolve();
787+
});
788+
}).then(() => {
789+
assert.deepStrictEqual(
790+
finalData.join(' '),
791+
'This This is This is testing This is testing the This is testing the brand'
792+
);
793+
});
794+
}
795+
717796
// When maxRetries are set to 2 then on the third error from the server gax
718797
// should throw an error that says the retry count has been exceeded.
719798
async function testShouldFailOnThirdError(client: SequenceServiceClient) {
Collapse file

‎packages/packages/google-gax/gax/test/unit/streaming.ts‎

Copy file name to clipboardExpand all lines: packages/packages/google-gax/gax/test/unit/streaming.ts
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,6 @@ describe('handles server streaming retries in gax when gaxStreamingRetries is en
13161316
const s = new PassThrough({
13171317
objectMode: true,
13181318
});
1319-
s.push('hello');
13201319
setImmediate(() => {
13211320
s.emit('metadata');
13221321
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.