Stmt timeout error can be sent after a CommandComplete

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Stmt timeout error can be sent after a CommandComplete
Date: 2026-01-13 09:20:32
Message-ID: CAO6_Xqqq2UAeRxrjxN9htu4RtvxJEWw4rLha4mPe5FOoZ2Byug@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

At the end of a command, disable_statement_timeout is called as the
timeout applies to a specific command and a CommandComplete message is
sent.

However, it's possible for the stmt timeout to have been fired between
the last message and the call to disable_statement_timeout. The
timeout won't be active anymore, so disable_timeout will be skipped.
However, the timeout is still queued, and the next call to
CHECK_FOR_INTERRUPTS will process and generate a stmt timeout error.

This leads to the confusing situation where we can have a
CompleteCommand message followed by a stmt timeout error for the same
command.

This patch fixes this issue by resetting the timeout indicator if the
timeout is inactive, relying on get_timeout_indicator to reset the
timeout indicator.

Regards,
Anthonin Bonnefoy

Attachment Content-Type Size
v1-0001-Reset-stmt-timeout-indicator-on-disable_statement.patch application/octet-stream 1.7 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Álvaro Herrera 2026-01-13 09:07:13 Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY