Skip to content

Fix for panic in rows.Next() when stored procedures emit NOTICE messages#188

Merged
sivaalamp merged 3 commits into
masterfrom
panic_stored_procedures_emit_notice_messages
Mar 12, 2026
Merged

Fix for panic in rows.Next() when stored procedures emit NOTICE messages#188
sivaalamp merged 3 commits into
masterfrom
panic_stored_procedures_emit_notice_messages

Conversation

@sivaalamp

@sivaalamp sivaalamp commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Problem:
When calling a stored procedure that raises one or more RAISE NOTICE messages before returning its result set, rows.Next() panics with:
panic: runtime error: index out of range [1] with length 1

Root cause:
The driver sizes the destination slice (dest []driver.Value) from the first RowDescription message it receives. When a stored procedure emits RAISE NOTICE messages, the protocol response interleaving can cause the driver to commit to a dest slice sized for fewer columns (e.g. 1) than the DataRow that arrives for the actual CALL result (e.g. 2 INOUT columns). The original loop iterated over rowCols.NumCols without any bounds check against dest, causing the out-of-bounds panic on the second column.

Fix:
Added expandColumnDefs(numCols uint16) on *rows (rows.go). When the first BEDataRowMsg is received during buffering, if the arriving DataRow has more fields than columnDefs currently describes, synthetic column definitions are appended to cover the gap. Synthetic entries use OID 0 so that rows.Next() returns raw wire bytes as a string rather than asserting a false specific type. database/sql's convertAssign correctly coerces these strings to the target Go types during Scan.

expandColumnDefs is called on the first BEDataRowMsg in both:

runSimpleStatement — simple query path
collectResults — prepared statement path (the path affected by this bug)
Additionally the BERowDescMsg handler in collectResults was updated to always prefer an execution-time RowDescription over the Describe-phase one (if no DataRows have been buffered yet), so that if Vertica ever fixes this behaviour the driver will automatically pick up complete type information without needing the synthetic fallback.

Test:
Added TestStoredProcedureWithNotice
Added TestStoredProcedureWithNoticeSimpleQuery

  • Creates a PLvSQL stored procedure (test_notice_proc) with two INOUT parameters that emits two RAISE NOTICE messages before returning
  • Wraps [rows.Next()] so that any panic surfaces as a clear failure rather than crashing the test binary
  • Iterates all result sets via NextResultSet() and dynamically sizes the Scan targets from Columns() to remain correct for any column count
  • Drops the procedure in a defer to leave the database clean

@sivaalamp sivaalamp requested review from sharmagot and removed request for mkottakota1 March 10, 2026 10:05
Comment thread rows.go
Comment thread stmt.go
@sivaalamp

Copy link
Copy Markdown
Collaborator Author
  1. The pipelines are failing because of recent license mandate, so a separate ticket is already created to fix the pipeline failure.
    https://ot-internal.saas.microfocus.com/ui/entity-navigation?p=4001/37001&entityType=work_item&id=5162476

  2. The tests are run locally and ensured everything is passed

image

@sharmagot

Copy link
Copy Markdown
Collaborator

The changes look good to me. Approving the MR.

@sharmagot sharmagot self-requested a review March 12, 2026 07:10

@sharmagot sharmagot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me. Approving the MR.

@sivaalamp sivaalamp merged commit b7c545b into master Mar 12, 2026
1 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants