Skip to content

fix(outputs.postgresql): report a missing table instead of panicking - #19608

Open
arpitjain099 wants to merge 1 commit into
influxdata:masterfrom
arpitjain099:fix/postgresql-nil-table-render
Open

fix(outputs.postgresql): report a missing table instead of panicking#19608
arpitjain099 wants to merge 1 commit into
influxdata:masterfrom
arpitjain099:fix/postgresql-nil-table-render

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

Fixes #19501.

Render builds allColumns with tcs.Concat(table.Columns) without checking table, and NewTable returns nil whenever the table name is empty. A nil table therefore segfaults inside the template render and takes the agent down, which is the crash in the report:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x6b5f965]
sqltemplate.(*Template).Render(...)
        plugins/outputs/postgresql/sqltemplate/template.go:397

I reproduced that exact frame from a unit test by handing Render the nil that NewTable("", "", nil) returns, so it is reachable from any caller that ends up with an empty table name, not only through the reported configuration.

Render now returns cannot render template without a table instead. The write then fails the way any other schema error does, gets logged by the table manager, and the agent keeps running.

To be clear about the scope: this stops the crash and turns it into a reportable error, but it does not explain how the table state reaches update with an empty name in the reporter's setup. That is worth chasing separately, and this change makes it visible in the logs instead of a stack trace.

TestRenderWithoutTable covers both directions, the nil table erroring and an ordinary table still rendering. It panics on master rather than failing.

go test ./plugins/outputs/postgresql/... passes.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@telegraf-tiger telegraf-tiger Bot added area/postgresql fix pr to fix corresponding bug plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Sep 2, 2026
@telegraf-tiger

telegraf-tiger Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

⚠️ This pull request increases the Telegraf binary size by 5.69 % for linux amd64 (new size: 325.8 MB, nightly size 308.2 MB)

📦 Click here to get additional PR build artifacts

Artifact URLs

. DEB . RPM . TAR . GZ . ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip
armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip
armhf.deb i386.rpm freebsd_armv7.tar.gz
i386.deb ppc64le.rpm freebsd_i386.tar.gz
mips.deb riscv64.rpm linux_amd64.tar.gz
mipsel.deb s390x.rpm linux_arm64.tar.gz
ppc64el.deb x86_64.rpm linux_armel.tar.gz
riscv64.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz

@srebhan

srebhan commented Sep 2, 2026

Copy link
Copy Markdown
Member

Thanks for your contribution @arpitjain099! Can you please restore the PR description template, especially the AI section, as we cannot review or merge your PR otherwise...

@srebhan srebhan added the waiting for response waiting for response from contributor label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/postgresql fix pr to fix corresponding bug plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins waiting for response waiting for response from contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

outputs.postgresql: nil pointer panic in sqltemplate.Template.Render when a metric has zero tags

2 participants