Skip to content

Commit 07d581b

Browse files
committed
Add recover blocks to all callback functions. Closes #199
1 parent f8f4d58 commit 07d581b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

fdw.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ func goFdwGetRelSize(state *C.FdwPlanState, root *C.PlannerInfo, rows *C.double,
100100

101101
//export goFdwGetPathKeys
102102
func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
103+
defer func() {
104+
if r := recover(); r != nil {
105+
log.Printf("[WARN] goFdwGetPathKeys failed with panic: %v", r)
106+
FdwError(fmt.Errorf("%v", r))
107+
}
108+
}()
109+
103110
pluginHub, err := hub.GetHub()
104111
if err != nil {
105112
FdwError(err)
@@ -149,6 +156,13 @@ func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
149156

150157
//export goFdwExplainForeignScan
151158
func goFdwExplainForeignScan(node *C.ForeignScanState, es *C.ExplainState) {
159+
defer func() {
160+
if r := recover(); r != nil {
161+
log.Printf("[WARN] goFdwExplainForeignScan failed with panic: %v", r)
162+
FdwError(fmt.Errorf("%v", r))
163+
}
164+
}()
165+
152166
s := GetExecState(node.fdw_state)
153167
if s == nil {
154168
return
@@ -163,6 +177,13 @@ func goFdwExplainForeignScan(node *C.ForeignScanState, es *C.ExplainState) {
163177

164178
//export goFdwBeginForeignScan
165179
func goFdwBeginForeignScan(node *C.ForeignScanState, eflags C.int) {
180+
defer func() {
181+
if r := recover(); r != nil {
182+
log.Printf("[WARN] goFdwExplainForeignScan failed with panic: %v", r)
183+
FdwError(fmt.Errorf("%v", r))
184+
}
185+
}()
186+
166187
logging.LogTime("[fdw] BeginForeignScan start")
167188
rel := BuildRelation(node.ss.ss_currentRelation)
168189
opts := GetFTableOptions(rel.ID)
@@ -288,13 +309,25 @@ func goFdwIterateForeignScan(node *C.ForeignScanState) *C.TupleTableSlot {
288309

289310
//export goFdwReScanForeignScan
290311
func goFdwReScanForeignScan(node *C.ForeignScanState) {
312+
defer func() {
313+
if r := recover(); r != nil {
314+
log.Printf("[WARN] goFdwReScanForeignScan failed with panic: %v", r)
315+
FdwError(fmt.Errorf("%v", r))
316+
}
317+
}()
291318
log.Printf("[TRACE] goFdwReScanForeignScan")
292319
// restart the scan
293320
goFdwBeginForeignScan(node, 0)
294321
}
295322

296323
//export goFdwEndForeignScan
297324
func goFdwEndForeignScan(node *C.ForeignScanState) {
325+
defer func() {
326+
if r := recover(); r != nil {
327+
log.Printf("[WARN] goFdwEndForeignScan failed with panic: %v", r)
328+
FdwError(fmt.Errorf("%v", r))
329+
}
330+
}()
298331
s := GetExecState(node.fdw_state)
299332
pluginHub, _ := hub.GetHub()
300333
if s != nil && pluginHub != nil {
@@ -308,6 +341,12 @@ func goFdwEndForeignScan(node *C.ForeignScanState) {
308341

309342
//export goFdwAbortCallback
310343
func goFdwAbortCallback() {
344+
defer func() {
345+
if r := recover(); r != nil {
346+
log.Printf("[WARN] goFdwAbortCallback failed with panic: %v", r)
347+
// DO NOT call FdwError or we will recurse
348+
}
349+
}()
311350
log.Printf("[TRACE] goFdwAbortCallback")
312351
if pluginHub, err := hub.GetHub(); err == nil {
313352
pluginHub.Abort()
@@ -351,6 +390,13 @@ func goFdwImportForeignSchema(stmt *C.ImportForeignSchemaStmt, serverOid C.Oid)
351390

352391
//export goFdwExecForeignInsert
353392
func goFdwExecForeignInsert(estate *C.EState, rinfo *C.ResultRelInfo, slot *C.TupleTableSlot, planSlot *C.TupleTableSlot) *C.TupleTableSlot {
393+
defer func() {
394+
if r := recover(); r != nil {
395+
log.Printf("[WARN] goFdwExecForeignInsert failed with panic: %v", r)
396+
FdwError(fmt.Errorf("%v", r))
397+
}
398+
}()
399+
354400
// get the connection from the relation namespace
355401
relid := rinfo.ri_RelationDesc.rd_id
356402
rel := C.RelationIdGetRelation(relid)

0 commit comments

Comments
 (0)