Skip to content

fix: Apply statement_timeout via SET instead of startup param#50

Merged
ivov merged 2 commits into
masterfrom
statement-timeout
Mar 25, 2026
Merged

fix: Apply statement_timeout via SET instead of startup param#50
ivov merged 2 commits into
masterfrom
statement-timeout

Conversation

@ivov
Copy link
Copy Markdown
Member

@ivov ivov commented Mar 20, 2026

Follow-up to n8n-io/n8n#27295

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/driver/postgres/PostgresDriver.ts">

<violation number="1" location="src/driver/postgres/PostgresDriver.ts:1539">
P2: Handle the promise returned by `client.query` (await or `.catch`) so errors from `SET statement_timeout` don’t become unhandled rejections.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Driver as PostgresDriver
    participant Pool as pg.Pool
    participant Client as pg.Client (Internal)
    participant DB as Postgres Server / RDS Proxy

    Note over Driver,DB: Pool Initialization

    Driver->>Pool: Instantiate Pool
    Note right of Driver: CHANGED: statement_timeout is no longer<br/>passed in the startup config object

    opt NEW: If options.statementTimeout is set
        Driver->>Pool: Register listener for 'connect' event
    end

    Note over Driver,DB: Connection Lifecycle (per new connection)

    Pool->>DB: Open physical connection
    DB-->>Pool: Connection established
    
    Pool->>Driver: Emit 'connect' event (Client instance)
    
    opt NEW: In 'connect' event handler
        Driver->>Client: NEW: query("SET statement_timeout = ...")
        Client->>DB: Execute SET command
        Note over Client,DB: Avoids startup parameter rejection<br/>by proxies (e.g., AWS RDS Proxy)
        DB-->>Client: Command complete
    end

    Driver->>Pool: pool.connect() (Request connection for usage)
    Pool-->>Driver: Return active Connection
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/driver/postgres/PostgresDriver.ts Outdated
@ivov ivov force-pushed the statement-timeout branch from 8763443 to 62f7d57 Compare March 20, 2026 08:53
@ivov ivov requested a review from tomi March 20, 2026 08:56
Comment thread src/driver/postgres/PostgresDriver.ts Outdated
pool.on("connect", (client: any) => {
client
.query(
`SET statement_timeout = ${options.statementTimeout}`,
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.

We also do SET for the schema in obtainMasterConnection. Would be nice to keep these per connection runtime configs in a single place. So either move this also there or move the SET search_path here

Move SET statement_timeout from pool connect event to obtainMasterConnection,
alongside SET search_path. Both are per-connection session settings and belong
in the same place. This also ensures the SET is awaited before the connection
is used, avoiding a potential race with the fire-and-forget pool event handler.
@ivov ivov requested a review from tomi March 25, 2026 09:46
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/driver/postgres/PostgresDriver.ts">

<violation number="1" location="src/driver/postgres/PostgresDriver.ts:1199">
P1: `statement_timeout` is now applied only on master connections, so replica/slave queries can run without the configured timeout.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

} else {
await connection.query("SET search_path TO public")
}
if (statementTimeout) {
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 25, 2026

Choose a reason for hiding this comment

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

P1: statement_timeout is now applied only on master connections, so replica/slave queries can run without the configured timeout.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/driver/postgres/PostgresDriver.ts, line 1199:

<comment>`statement_timeout` is now applied only on master connections, so replica/slave queries can run without the configured timeout.</comment>

<file context>
@@ -1189,13 +1189,19 @@ export class PostgresDriver implements Driver {
         } else {
             await connection.query("SET search_path TO public")
         }
+        if (statementTimeout) {
+            await connection.query(
+                `SET statement_timeout = ${statementTimeout}`,
</file context>
Fix with Cubic

Copy link
Copy Markdown
Collaborator

@tomi tomi left a comment

Choose a reason for hiding this comment

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

🚀

@ivov ivov merged commit 195ebdc into master Mar 25, 2026
5 checks passed
@ivov ivov deleted the statement-timeout branch March 25, 2026 11:24
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