GeezerVison is showing github.com — fix: Reset the retry counter to 0 when receiving data (#1604) · googleapis/google-cloud-node@5ab7a37
File treeExpand file treeCollapse file tree Open diff view settings packages/packages/google-gax/gax
Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -271,7 +271,7 @@ export class StreamProxy extends duplexify implements GRPCCallResult { | 271 | 271 | */ | 272 | 272 | streamHandoffHelper(stream: CancellableStream, retry: RetryOptions): void { | 273 | 273 | let enteredError = false; | 274 | | - const eventsToForward = ['metadata', 'response', 'status', 'data']; | | 274 | + const eventsToForward = ['metadata', 'response', 'status']; | 275 | 275 |
| 276 | 276 | eventsToForward.forEach(event => { | 277 | 277 | stream.on(event, this.emit.bind(this, event)); | @@ -282,6 +282,11 @@ export class StreamProxy extends duplexify implements GRPCCallResult { | 282 | 282 | this.streamHandoffErrorHandler(stream, retry, error); | 283 | 283 | }); | 284 | 284 |
| | 285 | + stream.on('data', (data: ResponseType) => { | | 286 | + this.retries = 0; | | 287 | + this.emit.bind(this, 'data')(data); | | 288 | + }); | | 289 | + | 285 | 290 | stream.on('end', () => { | 286 | 291 | if (!enteredError) { | 287 | 292 | enteredError = true; | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -80,6 +80,8 @@ async function testShowcase() { | 80 | 80 | const restClient = new EchoClient(restClientOpts); | 81 | 81 | const restClientCompat = new EchoClient(restClientOptsCompat); | 82 | 82 |
| | 83 | + await testResetRetriesToZero(grpcSequenceClientWithServerStreamingRetries); | | 84 | + | 83 | 85 | // assuming gRPC server is started locally | 84 | 86 | await testEcho(grpcClient); | 85 | 87 | await testEchoError(grpcClient); | @@ -714,6 +716,83 @@ async function testServerStreamingRetrieswithRetryRequestOptions( | 714 | 716 | }); | 715 | 717 | } | 716 | 718 |
| | 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 | + | 717 | 796 | // When maxRetries are set to 2 then on the third error from the server gax | 718 | 797 | // should throw an error that says the retry count has been exceeded. | 719 | 798 | async function testShouldFailOnThirdError(client: SequenceServiceClient) { | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -1316,7 +1316,6 @@ describe('handles server streaming retries in gax when gaxStreamingRetries is en | 1316 | 1316 | const s = new PassThrough({ | 1317 | 1317 | objectMode: true, | 1318 | 1318 | }); | 1319 | | - s.push('hello'); | 1320 | 1319 | setImmediate(() => { | 1321 | 1320 | s.emit('metadata'); | 1322 | 1321 | }); | |
|