Skip to content

Commit 72db53f

Browse files
committed
pass GRPC stream context to plugin rather than creating new one. #17
1 parent 9069309 commit 72db53f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

plugin/plugin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (p *Plugin) Execute(req *proto.ExecuteRequest, stream proto.WrapperPlugin_E
121121
// 3) Build row spawns goroutines for any required hydrate functions.
122122
// 4) When hydrate functions are complete, apply transforms to generate column values. When row is ready, send on rowChan
123123
// 5) Range over rowChan - for each row, send on results stream
124-
ctx := context.WithValue(context.Background(), context_key.Logger, p.Logger)
124+
ctx := context.WithValue(stream.Context(), context_key.Logger, p.Logger)
125125

126126
var matrixItem []map[string]interface{}
127127
var connection *Connection

plugin/query_data.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package plugin
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"log"
87
"sync"
@@ -55,9 +54,6 @@ type QueryData struct {
5554
listWg sync.WaitGroup
5655
// when executing parent child list calls, we cache the parent list result in the query data passed to the child list call
5756
parentItem interface{}
58-
59-
// there was an error streaming to the grpc stream
60-
streamingError error
6157
}
6258

6359
func newQueryData(queryContext *QueryContext, table *Table, stream proto.WrapperPlugin_ExecuteServer, connection *Connection, matrix []map[string]interface{}, connectionManager *connection_manager.Manager) *QueryData {
@@ -265,9 +261,11 @@ func (d *QueryData) verifyCallerIsListCall(callingFunction string) bool {
265261
}
266262

267263
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)
264+
// if the context is cancelled, panic to break out
265+
select {
266+
case <-d.stream.Context().Done():
267+
panic(contextCancelledError)
268+
default:
271269
}
272270

273271
// create rowData, passing matrixItem from context
@@ -292,8 +290,6 @@ func (d *QueryData) streamRows(_ context.Context, rowChan chan *proto.Row) error
292290
for {
293291
// wait for either an item or an error
294292
select {
295-
case <-d.stream.Context().Done():
296-
d.streamingError = errors.New(contextCancelledError)
297293
case err := <-d.errorChan:
298294
log.Printf("[ERROR] streamRows error chan select: %v\n", err)
299295
return err
@@ -306,10 +302,6 @@ func (d *QueryData) streamRows(_ context.Context, rowChan chan *proto.Row) error
306302
return nil
307303
}
308304
if err := d.streamRow(row); err != nil {
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-
313305
return err
314306
}
315307
}

0 commit comments

Comments
 (0)