Skip to content

Application Hangs on defer p.destructWG.Wait() in Docker Environment #37

@rubenhazelaar

Description

@rubenhazelaar

Description:
As described in issue #25, my application hangs on the statement defer p.destructWG.Wait(). Any deferred statement or code that should execute after defer pool.Close() does not run. This issue occurs when running the application in a Docker container (FROM golang:1.22-alpine) on a Windows host machine through Docker Desktop. I have not tested this in other environments.

Steps to Reproduce:

  1. Run the application in a Docker container with the base image golang:1.22-alpine.
  2. Execute the provided code snippet.
  3. Observe that the application hangs on defer p.destructWG.Wait().

Expected Behavior:
Deferred statements, including those after defer pool.Close(), should execute as expected.

Actual Behavior:
Deferred statements after defer pool.Close() do not execute, causing the application to hang.

Environment:

  • Docker base image: golang:1.22-alpine
  • Host OS: Windows (via Docker Desktop)

Additional Context:
This issue occurs in the context where an actual connection has not been made through the pool. Below is the simplified code used in my application:

package main

import (
	"context"
	"errors"
	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgxpool"
	"os"
)

func main() {
	err := run(context.Background())
	if err != nil {
		os.Exit(1)
	}
}

func run(ctx context.Context) error {
	// Create the pool in a run func which is called by main func

	poolConfig, err := pgxpool.ParseConfig(/* applicationConfig.Dsn */)
	if err != nil {
		return err
	}
	poolConfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
		// Here I register some custom types
		return nil
	}

	pool, err := pgxpool.NewWithConfig(ctx, poolConfig)
	if err != nil {
		return err
	}
	defer pool.Close()

	// More code where an error is returned from run to main func, like so:
	err = aCallWhichFails()
	if err != nil {
		return err
	}

	return nil
}

func aCallWhichFails() error {
	return errors.New("test")
}

Feel free to adjust any part of this as needed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions