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: don't emit error event during stream handoff (#1592) · googleapis/google-cloud-node@f75231c

File tree

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

‎packages/packages/google-gax/gax/src/streamingRetryRequest.ts‎

Copy file name to clipboardExpand all lines: packages/packages/google-gax/gax/src/streamingRetryRequest.ts
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ export function streamingRetryRequest(opts: streamingRetryRequestOptions) {
106106
// No more attempts need to be made, just continue on.
107107
retryStream.emit('response', response);
108108
delayStream.pipe(retryStream);
109-
requestStream.on('error', (err: GoogleError) => {
110-
retryStream.destroy(err);
109+
requestStream.on('error', () => {
110+
// retryStream must be destroyed here for the stream handoff part of retries to function properly
111+
// but the error event should not be passed - if it emits as part of .destroy()
112+
// it will bubble up early to the caller
113+
retryStream.destroy();
111114
});
112115
}
113116
}
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
+47-69Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ async function testWait(client: EchoClient) {
467467
assert.deepStrictEqual(response.content, request.success.content);
468468
}
469469

470+
// a successful streaming call that has retry options passed but does not retry
470471
async function testServerStreamingRetryOptions(client: SequenceServiceClient) {
471472
const finalData: string[] = [];
472473
const backoffSettings = createBackoffSettings(
@@ -495,7 +496,7 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) {
495496
);
496497

497498
const response = await client.createStreamingSequence(request);
498-
await new Promise<void>(resolve => {
499+
await new Promise<void>((resolve, reject) => {
499500
const sequence = response[0];
500501

501502
const attemptRequest =
@@ -509,8 +510,9 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) {
509510
attemptStream.on('data', (response: {content: string}) => {
510511
finalData.push(response.content);
511512
});
512-
attemptStream.on('error', () => {
513-
//Do Nothing
513+
attemptStream.on('error', (error: GoogleError) => {
514+
// should not reach this
515+
reject(error);
514516
});
515517
attemptStream.on('end', () => {
516518
attemptStream.end();
@@ -524,6 +526,7 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) {
524526
});
525527
}
526528

529+
// a streaming call that retries two times and finishes successfully
527530
async function testServerStreamingRetrieswithRetryOptions(
528531
client: SequenceServiceClient
529532
) {
@@ -554,7 +557,7 @@ async function testServerStreamingRetrieswithRetryOptions(
554557
);
555558

556559
const response = await client.createStreamingSequence(request);
557-
await new Promise<void>(resolve => {
560+
await new Promise<void>((resolve, reject) => {
558561
const sequence = response[0];
559562

560563
const attemptRequest =
@@ -568,8 +571,8 @@ async function testServerStreamingRetrieswithRetryOptions(
568571
attemptStream.on('data', (response: {content: string}) => {
569572
finalData.push(response.content);
570573
});
571-
attemptStream.on('error', () => {
572-
//Do Nothing
574+
attemptStream.on('error', error => {
575+
reject(error);
573576
});
574577
attemptStream.on('end', () => {
575578
attemptStream.end();
@@ -583,6 +586,7 @@ async function testServerStreamingRetrieswithRetryOptions(
583586
});
584587
}
585588

589+
// a streaming call that retries twice using shouldRetryFn and finally succeeds
586590
async function testServerStreamingRetriesWithShouldRetryFn(
587591
client: SequenceServiceClient
588592
) {
@@ -617,7 +621,7 @@ async function testServerStreamingRetriesWithShouldRetryFn(
617621
);
618622

619623
const response = await client.createStreamingSequence(request);
620-
await new Promise<void>(resolve => {
624+
await new Promise<void>((resolve, reject) => {
621625
const sequence = response[0];
622626
const attemptRequest =
623627
new protos.google.showcase.v1beta1.AttemptStreamingSequenceRequest();
@@ -630,8 +634,9 @@ async function testServerStreamingRetriesWithShouldRetryFn(
630634
attemptStream.on('data', (response: {content: string}) => {
631635
finalData.push(response.content);
632636
});
633-
attemptStream.on('error', () => {
634-
// Do nothing
637+
attemptStream.on('error', error => {
638+
// should not reach this
639+
reject(error);
635640
});
636641
attemptStream.on('end', () => {
637642
attemptStream.end();
@@ -645,6 +650,7 @@ async function testServerStreamingRetriesWithShouldRetryFn(
645650
});
646651
}
647652

653+
// streaming call that retries twice using RetryRequestOptions instead of RetryOptions
648654
async function testServerStreamingRetrieswithRetryRequestOptions(
649655
client: SequenceServiceClient
650656
) {
@@ -676,7 +682,7 @@ async function testServerStreamingRetrieswithRetryRequestOptions(
676682
);
677683

678684
const response = await client.createStreamingSequence(request);
679-
await new Promise<void>(resolve => {
685+
await new Promise<void>((resolve, reject) => {
680686
const sequence = response[0];
681687

682688
const attemptRequest =
@@ -690,8 +696,8 @@ async function testServerStreamingRetrieswithRetryRequestOptions(
690696
attemptStream.on('data', (response: {content: string}) => {
691697
finalData.push(response.content);
692698
});
693-
attemptStream.on('error', () => {
694-
// Do Nothing
699+
attemptStream.on('error', error => {
700+
reject(error);
695701
});
696702
attemptStream.on('end', () => {
697703
attemptStream.end();
@@ -704,6 +710,8 @@ async function testServerStreamingRetrieswithRetryRequestOptions(
704710
);
705711
});
706712
}
713+
714+
// streaming call that retries twice with RetryRequestOpsions and resumes from where it left off
707715
async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrategy(
708716
client: SequenceServiceClient
709717
) {
@@ -748,7 +756,7 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate
748756
'This is testing the brand new and shiny StreamingSequence server 3'
749757
);
750758
const response = await client.createStreamingSequence(request);
751-
await new Promise<void>(resolve => {
759+
await new Promise<void>((resolve, reject) => {
752760
const sequence = response[0];
753761

754762
const attemptRequest =
@@ -762,8 +770,8 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate
762770
attemptStream.on('data', (response: {content: string}) => {
763771
finalData.push(response.content);
764772
});
765-
attemptStream.on('error', () => {
766-
// do nothing
773+
attemptStream.on('error', error => {
774+
reject(error);
767775
});
768776
attemptStream.on('end', () => {
769777
attemptStream.end();
@@ -777,6 +785,7 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate
777785
});
778786
}
779787

788+
// retries twice but fails with an error not from the streaming sequence
780789
async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResumptionStrategy(
781790
client: SequenceServiceClient
782791
) {
@@ -816,9 +825,8 @@ async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResum
816825
[1, 2, 11],
817826
'This is testing the brand new and shiny StreamingSequence server 3'
818827
);
819-
const allowedCodes = [4, 14];
820828
const response = await client.createStreamingSequence(request);
821-
await new Promise<void>((_, reject) => {
829+
await new Promise<void>(resolve => {
822830
const sequence = response[0];
823831

824832
const attemptRequest =
@@ -831,21 +839,14 @@ async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResum
831839
);
832840

833841
attemptStream.on('error', (e: GoogleError) => {
834-
if (!allowedCodes.includes(e.code!)) {
835-
reject(e);
836-
}
842+
assert.strictEqual(e.code, 3);
843+
assert.match(e.note!, /not classified as transient/);
844+
resolve();
837845
});
838-
}).then(
839-
() => {
840-
assert(false);
841-
},
842-
(err: GoogleError) => {
843-
assert.strictEqual(err.code, 3);
844-
assert.match(err.note!, /not classified as transient/);
845-
}
846-
);
846+
});
847847
}
848848

849+
// fails on the first error in the sequence
849850
async function testServerStreamingThrowsClassifiedTransientErrorNote(
850851
client: SequenceServiceClient
851852
) {
@@ -875,7 +876,7 @@ async function testServerStreamingThrowsClassifiedTransientErrorNote(
875876
);
876877

877878
const response = await client.createStreamingSequence(request);
878-
await new Promise<void>((_, reject) => {
879+
await new Promise<void>(resolve => {
879880
const sequence = response[0];
880881

881882
const attemptRequest =
@@ -887,21 +888,14 @@ async function testServerStreamingThrowsClassifiedTransientErrorNote(
887888
settings
888889
);
889890
attemptStream.on('error', (e: GoogleError) => {
890-
if (!allowedCodes.includes(e.code!)) {
891-
reject(e);
892-
}
891+
assert.strictEqual(e.code, 14);
892+
assert.match(e.note!, /not classified as transient/);
893+
resolve();
893894
});
894-
}).then(
895-
() => {
896-
assert(false);
897-
},
898-
(err: GoogleError) => {
899-
assert.strictEqual(err.code, 14);
900-
assert.match(err.note!, /not classified as transient/);
901-
}
902-
);
895+
});
903896
}
904897

898+
// retries once and fails on the second error in the sequence
905899
async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote(
906900
client: SequenceServiceClient
907901
) {
@@ -931,7 +925,7 @@ async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote(
931925
);
932926

933927
const response = await client.createStreamingSequence(request);
934-
await new Promise<void>((_, reject) => {
928+
await new Promise<void>(resolve => {
935929
const sequence = response[0];
936930

937931
const attemptRequest =
@@ -943,19 +937,11 @@ async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote(
943937
settings
944938
);
945939
attemptStream.on('error', (e: GoogleError) => {
946-
if (!allowedCodes.includes(e.code!)) {
947-
reject(e);
948-
}
940+
assert.strictEqual(e.code, 4);
941+
assert.match(e.note!, /not classified as transient/);
942+
resolve();
949943
});
950-
}).then(
951-
() => {
952-
assert(false);
953-
},
954-
(err: GoogleError) => {
955-
assert.strictEqual(err.code, 4);
956-
assert.match(err.note!, /not classified as transient/);
957-
}
958-
);
944+
});
959945
}
960946

961947
async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries(
@@ -988,7 +974,7 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries(
988974
);
989975

990976
const response = await client.createStreamingSequence(request);
991-
await new Promise<void>((_, reject) => {
977+
await new Promise<void>(resolve => {
992978
const sequence = response[0];
993979

994980
const attemptRequest =
@@ -1000,22 +986,14 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries(
1000986
settings
1001987
);
1002988
attemptStream.on('error', (e: GoogleError) => {
1003-
if (!allowedCodes.includes(e.code!)) {
1004-
reject(e);
1005-
}
1006-
});
1007-
}).then(
1008-
() => {
1009-
assert(false);
1010-
},
1011-
(err: GoogleError) => {
1012-
assert.strictEqual(err.code, 3);
989+
assert.strictEqual(e.code, 3);
1013990
assert.match(
1014-
err.message,
991+
e.message,
1015992
/Cannot set both totalTimeoutMillis and maxRetries/
1016993
);
1017-
}
1018-
);
994+
resolve();
995+
});
996+
});
1019997
}
1020998

1021999
async function main() {

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.