Skip to content

ERROR: DISCARD ALL cannot run inside a transaction block when connection closed uncleanly #64

Closed
@drdrsh

Description

@drdrsh

Describe the bug

I am working on a test bench to test some edge cases against pgcat. Opening a transaction and then closing the client connection causes pgcat to issue ROLLBACK; DISCARD ALL, however this behavior triggers ERROR: DISCARD ALL cannot run inside a transaction block error on the server. Might be something wrong with my setup or an issue with pgcat

To Reproduce
Put the following 3 files in the same directory and run docker compose up

docker-compose.yml

version: '3'
services:
  pg:
    image: postgres:12-bullseye
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
      POSTGRES_DB: main_db
      POSTGRES_USER: main_user

  pgcat:
    build: https://github.com/levkk/pgcat.git#main
    restart: always
    command: ["pgcat", "/etc/pgcat/pgcat.toml"]
    links:
      - pg
    volumes:
      - "./config.toml:/etc/pgcat/pgcat.toml"

  app:
    image: ruby
    links:
      - pgcat
    volumes:
      - "./entrypoint.rb:/app/entrypoint.rb"
    command: bash -c "gem install pg && ruby /app/entrypoint.rb"

entrypoint.rb

require 'pg'
$stdout.sync = true

def poorly_behaved_client
    conn = PG::connect("postgres://main_user:@pgcat:5432/main_db")
    conn.async_exec("BEGIN")
    conn.async_exec("SELECT 1")
    conn.close
rescue Exception => e
    puts "Encountered #{e}"
end

sleep 5
loop { poorly_behaved_client }

config.toml

[general]
host = "0.0.0.0"
port = 5432
pool_size = 5
pool_mode = "transaction"
connect_timeout = 5000
healthcheck_timeout = 1000000
ban_time = 1 # Seconds
[user]
name = "main_user"
password = ""
[shards]
[shards.0]
servers = [[ "pg", 5432, "primary" ]]
database = "main_db"
[query_router]
default_role = "primary"
query_parser_enabled = false
primary_reads_enabled = false
sharding_function = "pg_bigint_hash"

Expected behavior
No server errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions