Skip to content

DISCARD PACKAGE can crash cached PL/iSQL callers #1452

Open

Description

@Z95-cmyk

Problem

A standalone PL/iSQL function that calls a package function can retain an FmgrInfo.fn_extra entry across DISCARD PACKAGE. Package cleanup frees the compiled dependent function but leaves its cached tuple identity valid, so the next invocation can treat the emptied function structure as reusable. The result is a backend segmentation fault.

Cached package FuncExpr.parent_func pointers and rebuilt function dependency lists can also outlive the package memory context or retain stale links after a reset.

This was found while separating correctness work from the package cleanup performance change in #1426. It was discovered by source inspection and a local regression reproducer, not from a reported production incident.

Reproduction

  1. Create a package function.
  2. Create and invoke a standalone PL/iSQL function that calls it.
  3. Prepare and execute a direct package call.
  4. Run DISCARD PACKAGE.
  5. Invoke the standalone function again.

On the current base revision, step 5 terminates the backend with SIGSEGV.

Expected outcome

  • invalidate the cached dependent-function tuple identity before freeing its compiled tree
  • refresh package function expressions against the current package cache entry before dereferencing parent_func
  • clear removed dependency lists so rebuilt functions do not retain stale links
  • add a regression test covering cached callers, prepared plans, and repeated DISCARD PACKAGE
  • demonstrate that the regression fails on the base revision and passes with the fix

Activity

  1. hanjianqiao commented on Sep 2, 2026

    @hanjianqiao
    Collaborator

    ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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