Skip to content

Commit ba544f6

Browse files
authored
Fix nil reference panic when a scan fails to start - do not add an iterator to Hub.runningIterators until scan is started successfully. Closes #298
1 parent 60e421f commit ba544f6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

fdw.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func init() {
6464
func goFdwGetRelSize(state *C.FdwPlanState, root *C.PlannerInfo, rows *C.double, width *C.int, baserel *C.RelOptInfo) {
6565
logging.ClearProfileData()
6666

67+
log.Printf("[TRACE] goFdwGetRelSize")
68+
6769
pluginHub, err := hub.GetHub()
6870
if err != nil {
6971
FdwError(err)
@@ -110,6 +112,7 @@ func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
110112
}
111113
}()
112114

115+
log.Printf("[TRACE] goFdwGetPathKeys")
113116
pluginHub, err := hub.GetHub()
114117
if err != nil {
115118
FdwError(err)
@@ -167,6 +170,7 @@ func goFdwExplainForeignScan(node *C.ForeignScanState, es *C.ExplainState) {
167170
}
168171
}()
169172

173+
log.Printf("[TRACE] goFdwExplainForeignScan")
170174
s := GetExecState(node.fdw_state)
171175
if s == nil {
172176
return
@@ -188,6 +192,7 @@ func goFdwBeginForeignScan(node *C.ForeignScanState, eflags C.int) {
188192
FdwError(fmt.Errorf("%v", r))
189193
}
190194
}()
195+
log.Printf("[TRACE] goFdwBeginForeignScan")
191196
// read the explain flag
192197
explain := eflags&C.EXEC_FLAG_EXPLAIN_ONLY == C.EXEC_FLAG_EXPLAIN_ONLY
193198

hub/hub.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const (
3434

3535
// Hub is a structure representing plugin hub
3636
type Hub struct {
37-
connections *connectionFactory
37+
connections *connectionFactory
38+
39+
// list of iterators currently executing scans
3840
runningIterators []Iterator
3941

4042
// if the cache is enabled/disabled by a metacommand, this will be non null
@@ -308,8 +310,6 @@ func (h *Hub) GetIterator(columns []string, quals *proto.Quals, unhandledRestric
308310
return nil, err
309311
}
310312

311-
// store the iterator
312-
h.addIterator(iterator)
313313
return iterator, nil
314314
}
315315

@@ -389,7 +389,6 @@ func (h *Hub) GetRelSize(columns []string, quals []*proto.Qual, opts types.Optio
389389
// For example, the return value corresponding to the previous scenario would be::
390390
// [(('id',), 1)]
391391
func (h *Hub) GetPathKeys(opts types.Options) ([]types.PathKey, error) {
392-
393392
connectionName := opts["connection"]
394393
table := opts["table"]
395394

@@ -698,6 +697,10 @@ func (h *Hub) StartScan(i Iterator) error {
698697
return err
699698
}
700699
iterator.Start(stream, ctx, cancel)
700+
701+
// add iterator to running list
702+
h.addIterator(iterator)
703+
701704
return nil
702705
}
703706

quals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func restrictionsToQuals(node *C.ForeignScanState, cinfos *conversionInfos) (qua
7272
log.Printf("[TRACE] %s", grpc.QualToString(q))
7373
}
7474
if unhandledRestrictions > 0 {
75-
log.Printf("[WARN] RestrictionsToQuals: failed to convert %s %s to quals",
75+
log.Printf("[WARN] RestrictionsToQuals: failed to convert %d %s to quals",
7676
unhandledRestrictions,
7777
pluralize.NewClient().Pluralize("restriction", unhandledRestrictions, false))
7878
}

0 commit comments

Comments
 (0)