@@ -2,6 +2,7 @@ package plugin
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"log"
7
8
"sync"
@@ -54,6 +55,9 @@ type QueryData struct {
54
55
listWg sync.WaitGroup
55
56
// when executing parent child list calls, we cache the parent list result in the query data passed to the child list call
56
57
parentItem interface {}
58
+
59
+ // there was an error streaming to the grpc stream
60
+ streamingError error
57
61
}
58
62
59
63
func newQueryData (queryContext * QueryContext , table * Table , stream proto.WrapperPlugin_ExecuteServer , connection * Connection , matrix []map [string ]interface {}, connectionManager * connection_manager.Manager ) * QueryData {
@@ -261,6 +265,11 @@ func (d *QueryData) verifyCallerIsListCall(callingFunction string) bool {
261
265
}
262
266
263
267
func (d * QueryData ) streamLeafListItem (ctx context.Context , item interface {}) {
268
+ if d .streamingError != nil {
269
+ // if there is streaming error, panic to force exit thread - this will be recovered higher up
270
+ panic (d .streamingError )
271
+ }
272
+
264
273
// create rowData, passing matrixItem from context
265
274
rd := newRowData (d , item )
266
275
rd .matrixItem = GetMatrixItem (ctx )
@@ -283,6 +292,8 @@ func (d *QueryData) streamRows(_ context.Context, rowChan chan *proto.Row) error
283
292
for {
284
293
// wait for either an item or an error
285
294
select {
295
+ case <- d .stream .Context ().Done ():
296
+ d .streamingError = errors .New (contextCancelledError )
286
297
case err := <- d .errorChan :
287
298
log .Printf ("[ERROR] streamRows error chan select: %v\n " , err )
288
299
return err
@@ -295,7 +306,10 @@ func (d *QueryData) streamRows(_ context.Context, rowChan chan *proto.Row) error
295
306
return nil
296
307
}
297
308
if err := d .streamRow (row ); err != nil {
298
- log .Printf ("[ERROR] stream.Send returned error: %v\n " , err )
309
+ // if there was an error streaming, store in d.streamingError
310
+ // - this is checked by the thread streaming list items and will cause it to terminate
311
+ d .streamingError = err
312
+
299
313
return err
300
314
}
301
315
}
0 commit comments