Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Expire idle connections no longer acquired during lifetime" #958

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

jkaflik
Copy link
Contributor

@jkaflik jkaflik commented Apr 3, 2023

Reproduced with following test case that driver logic runs into race condition due to idle connection close:

package issues

import (
	"context"
	"github.com/ClickHouse/clickhouse-go/v2"
	clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
	"github.com/stretchr/testify/require"
	"testing"
	"time"
)

func Test957(t *testing.T) {
	// given
	ctx := context.Background()
	testEnv, err := clickhouse_tests.GetTestEnvironment(testSet)
	require.NoError(t, err)

	// when the client is configured to use the test environment
	opts := clickhouse_tests.ClientOptionsFromEnv(testEnv, clickhouse.Settings{})
	opts.Debug = true
	opts.Debugf = func(format string, v ...interface{}) {
		t.Logf(format, v...)
	}
	// and the client is configured to have only 1 connection
	opts.MaxIdleConns = 2
	opts.MaxOpenConns = 1
	// and the client is configured to have a connection lifetime of 1/10 of a second
	opts.ConnMaxLifetime = time.Second / 10
	conn, err := clickhouse.Open(&opts)
	require.NoError(t, err)

	// then the client should be able to execute queries for 1 second
	deadline := time.Now().Add(time.Second)
	for time.Now().Before(deadline) {
		_, err := conn.Query(ctx, "SELECT 1")
		require.NoError(t, err)
	}
}

Reverts #945

@jkaflik jkaflik merged commit dd94572 into main Apr 3, 2023
@jkaflik jkaflik deleted the revert-945-expire-idle-conns branch May 5, 2023 16:17
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.

1 participant