@@ -244,40 +244,49 @@ func (it *storageArrowIterator) processStream(readStream string) {
244
244
Offset : offset ,
245
245
})
246
246
if err != nil {
247
- if it .rs .ctx .Err () != nil { // context cancelled, don't try again
247
+ serr := it .handleProcessStreamError (readStream , bo , err )
248
+ if serr != nil {
248
249
return
249
250
}
250
- backoff , shouldRetry := retryReadRows (bo , err )
251
- if shouldRetry {
252
- if err := gax .Sleep (it .rs .ctx , backoff ); err != nil {
253
- return // context cancelled
254
- }
255
- continue
256
- }
257
- it .errs <- fmt .Errorf ("failed to read rows on stream %s: %w" , readStream , err )
258
251
continue
259
252
}
260
253
offset , err = it .consumeRowStream (readStream , rowStream , offset )
261
254
if errors .Is (err , io .EOF ) {
262
255
return
263
256
}
264
257
if err != nil {
265
- if it .rs .ctx .Err () != nil { // context cancelled, don't queue error
258
+ serr := it .handleProcessStreamError (readStream , bo , err )
259
+ if serr != nil {
266
260
return
267
261
}
268
- backoff , shouldRetry := retryReadRows (bo , err )
269
- if shouldRetry {
270
- if err := gax .Sleep (it .rs .ctx , backoff ); err != nil {
271
- return // context cancelled
272
- }
273
- continue
274
- }
275
- it .errs <- fmt .Errorf ("failed to read rows on stream %s: %w" , readStream , err )
276
262
// try to re-open row stream with updated offset
277
263
}
278
264
}
279
265
}
280
266
267
+ // handleProcessStreamError check if err is retryable,
268
+ // waiting with exponential backoff in that scenario.
269
+ // If error is not retryable, queue up err to be sent to user.
270
+ // Return error if should exit the goroutine.
271
+ func (it * storageArrowIterator ) handleProcessStreamError (readStream string , bo gax.Backoff , err error ) error {
272
+ if it .rs .ctx .Err () != nil { // context cancelled, don't try again
273
+ return it .rs .ctx .Err ()
274
+ }
275
+ backoff , shouldRetry := retryReadRows (bo , err )
276
+ if shouldRetry {
277
+ if err := gax .Sleep (it .rs .ctx , backoff ); err != nil {
278
+ return err // context cancelled
279
+ }
280
+ return nil
281
+ }
282
+ select {
283
+ case it .errs <- fmt .Errorf ("failed to read rows on stream %s: %w" , readStream , err ):
284
+ return nil
285
+ case <- it .rs .ctx .Done ():
286
+ return context .Canceled
287
+ }
288
+ }
289
+
281
290
func retryReadRows (bo gax.Backoff , err error ) (time.Duration , bool ) {
282
291
s , ok := status .FromError (err )
283
292
if ! ok {
0 commit comments