Skip to content

Clarify nested defer pattern and fix incorrect log message in fdw.go #623

@e-gineer

Description

@e-gineer

Description

The goFdwBeginForeignScan() function in fdw.go has nested defer statements for panic recovery, but the code lacks comments explaining why this pattern is used. Additionally, the outer defer has an incorrect log message.

Current Code Issues

1. Incorrect log message

The outer defer logs goFdwExplainForeignScan but we're in goFdwBeginForeignScan:

func goFdwBeginForeignScan(node *C.ForeignScanState, eflags C.int) {
    defer func() {
        if r := recover(); r != nil {
            log.Printf("[WARN] goFdwExplainForeignScan failed with panic: %v", r)  // WRONG!
            // ...
        }
    }()

2. Missing documentation

The nested defer pattern is intentional but not documented:

defer func() { /* outer recover */ }()
// ... early init code ...
defer func() { /* inner recover */ }()
// ... main processing ...

Proposed Fix

  1. Fix the log message to say goFdwBeginForeignScan
  2. Add comments explaining why nested defers exist:
    • Outer: catches panics during early initialization
    • Inner: catches panics during main scan processing

Impact

  • Risk: None - Documentation only
  • Functionality: No behavioral change
  • Benefit: Easier maintenance and debugging

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions