Skip to content

Elixir operations with mode: :savepoint leave a wait_event='ClientRead' transaction hanging #1314

Description

@kzemek

PgDog version
v0.1.49, v0.1.51 & main

Description
When running Elixir's Postgrex and using its mode: :savepoint feature, Elixir side times out while PgDog side leaves the connection in a wait_event='ClientRead' transaction.


Here's the simplest repro, you can run it with elixir repro.exs:

Mix.install([{:postgrex, "~> 0.19"}])

{:ok, conn} =
  Postgrex.start_link(
    hostname: "127.0.0.1",
    port: 6432,
    username: "postgres",
    password: "postgres",
    database: "postgres"
  )

result =
	Postgrex.transaction(
	  conn,
	  fn c -> Postgrex.query(c, "SELECT 1/0", [], mode: :savepoint) end,
	  timeout: 5_000
	)

dbg(result)

then verify the hanging transaction:

SELECT pid, state, wait_event, query FROM pg_stat_activity WHERE wait_event = 'ClientRead'

Postgrex is doing

Query("BEGIN")
Query("SAVEPOINT postgrex_query")
Bind
Execute
Query("RELEASE SAVEPOINT postgrex_query")

it doesn't do Sync, which seems to be what trips PgDog here, as ErrorResponse handling re-queues ReadyForQuery regardless if Sync was sent. Best I can tell, what Postgrex does is unique but legal.

Logs

pgdog-trace-full.log

Configuration

The example Docker compose configuration from the repo. Tested in both sharded and unsharded modes just in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions