From 3e98b1485942b60bc8e6fad0f123807710c51ab2 Mon Sep 17 00:00:00 2001 From: w1am <33353798+w1am@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:42:21 +0400 Subject: [PATCH 1/5] Fix calls hanging and Close panicking after discovery fails --- kurrentdb/client.go | 44 ++++---- kurrentdb/connection_test.go | 52 +++++++++ kurrentdb/endpoint.go | 23 ++-- kurrentdb/impl.go | 104 ++++++++++++------ kurrentdb/operations.go | 4 +- .../persistent_subscription_http_client.go | 6 +- kurrentdb/projection_client.go | 20 ++-- 7 files changed, 168 insertions(+), 85 deletions(-) create mode 100644 kurrentdb/connection_test.go diff --git a/kurrentdb/client.go b/kurrentdb/client.go index e19bc1f..91c6227 100644 --- a/kurrentdb/client.go +++ b/kurrentdb/client.go @@ -54,7 +54,7 @@ func (client *Client) AppendToStream( events ...EventData, ) (*WriteResult, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -203,7 +203,7 @@ func (client *Client) MultiStreamAppend( } } - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -326,7 +326,7 @@ func (client *Client) AppendRecords( } } - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -501,7 +501,7 @@ func (client *Client) DeleteStream( opts DeleteStreamOptions, ) (*DeleteResult, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(parent) if err != nil { return nil, err } @@ -531,7 +531,7 @@ func (client *Client) TombstoneStream( opts TombstoneStreamOptions, ) (*DeleteResult, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(parent) if err != nil { return nil, err } @@ -560,7 +560,7 @@ func (client *Client) ReadStream( ) (*ReadStream, error) { opts.setDefaults() readRequest := toReadStreamRequest(streamID, opts.Direction, opts.From, count, opts.ResolveLinkTos) - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -576,7 +576,7 @@ func (client *Client) ReadAll( count uint64, ) (*ReadStream, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -595,7 +595,7 @@ func (client *Client) SubscribeToStream( opts SubscribeToStreamOptions, ) (*Subscription, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(parent) if err != nil { return nil, err } @@ -640,7 +640,7 @@ func (client *Client) SubscribeToAll( opts SubscribeToAllOptions, ) (*Subscription, error) { opts.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(parent) if err != nil { return nil, err } @@ -693,7 +693,7 @@ func (client *Client) SubscribeToPersistentSubscription( options SubscribeToPersistentSubscriptionOptions, ) (*PersistentSubscription, error) { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return nil, err } @@ -718,7 +718,7 @@ func (client *Client) SubscribeToPersistentSubscriptionToAll( options SubscribeToPersistentSubscriptionOptions, ) (*PersistentSubscription, error) { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return nil, err } @@ -751,7 +751,7 @@ func (client *Client) CreatePersistentSubscription( options PersistentStreamSubscriptionOptions, ) error { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -776,7 +776,7 @@ func (client *Client) CreatePersistentSubscriptionToAll( options PersistentAllSubscriptionOptions, ) error { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -818,7 +818,7 @@ func (client *Client) UpdatePersistentSubscription( options PersistentStreamSubscriptionOptions, ) error { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -839,7 +839,7 @@ func (client *Client) UpdatePersistentSubscriptionToAll( options PersistentAllSubscriptionOptions, ) error { options.setDefaults() - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -860,7 +860,7 @@ func (client *Client) DeletePersistentSubscription( groupName string, options DeletePersistentSubscriptionOptions, ) error { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -875,7 +875,7 @@ func (client *Client) DeletePersistentSubscriptionToAll( groupName string, options DeletePersistentSubscriptionOptions, ) error { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -900,7 +900,7 @@ func (client *Client) ReplayParkedMessagesToAll(ctx context.Context, groupName s } func (client *Client) replayParkedMessages(ctx context.Context, streamName string, groupName string, options ReplayParkedMessagesOptions) error { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -939,7 +939,7 @@ func (client *Client) ListPersistentSubscriptionsToAll(ctx context.Context, opti } func (client *Client) listPersistentSubscriptionsInternal(ctx context.Context, streamName *string, options ListPersistentSubscriptionsOptions) ([]PersistentSubscriptionInfo, error) { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return nil, err } @@ -971,7 +971,7 @@ func (client *Client) GetPersistentSubscriptionInfoToAll(ctx context.Context, gr } func (client *Client) getPersistentSubscriptionInfoInternal(ctx context.Context, streamName *string, groupName string, options GetPersistentSubscriptionOptions) (*PersistentSubscriptionInfo, error) { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return nil, err } @@ -996,7 +996,7 @@ func (client *Client) getPersistentSubscriptionInfoInternal(ctx context.Context, // RestartPersistentSubscriptionSubsystem Restarts the persistent subscription subsystem on the server. func (client *Client) RestartPersistentSubscriptionSubsystem(ctx context.Context, options RestartPersistentSubscriptionSubsystemOptions) error { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return err } @@ -1041,7 +1041,7 @@ func readInternal( } func (client *Client) Gossip(ctx context.Context) ([]*gossip.MemberInfo, error) { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return nil, err diff --git a/kurrentdb/connection_test.go b/kurrentdb/connection_test.go new file mode 100644 index 0000000..3f17470 --- /dev/null +++ b/kurrentdb/connection_test.go @@ -0,0 +1,52 @@ +package kurrentdb + +import ( + "context" + "net" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestDiscoveryFailureReleasesConcurrentCallers(t *testing.T) { + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(t, err) + defer listener.Close() + + config, err := ParseConnectionString("kurrentdb://" + listener.Addr().String() + "?tls=false&maxDiscoverAttempts=1&gossipTimeout=1&discoveryInterval=100") + require.NoError(t, err) + + for _, timeout := range []time.Duration{0, 250 * time.Millisecond} { + client, err := NewClient(config) + require.NoError(t, err) + + errs := make(chan error, 2) + for i := 0; i < 2; i++ { + go func() { + ctx := context.Background() + if timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, timeout) + defer cancel() + } + _, err := client.ReadStream(ctx, "repro", ReadStreamOptions{}, 1) + errs <- err + }() + } + + for i := 0; i < 2; i++ { + select { + case err := <-errs: + require.Error(t, err) + if timeout == 0 { + require.ErrorContains(t, err, "maximum discovery attempt count reached") + } + case <-time.After(5 * time.Second): + t.Fatalf("caller still blocked (timeout %v)", timeout) + } + } + + require.NoError(t, client.Close()) + } +} diff --git a/kurrentdb/endpoint.go b/kurrentdb/endpoint.go index cfea8cf..9dd0a09 100644 --- a/kurrentdb/endpoint.go +++ b/kurrentdb/endpoint.go @@ -7,7 +7,6 @@ import ( "strconv" "strings" "sync" - "sync/atomic" "google.golang.org/grpc/credentials" ) @@ -90,21 +89,15 @@ func clientPerRPCCredentials(config Configuration) credentials.PerRPCCredentials } func newGrpcClient(config Configuration) *grpcClient { - channel := make(chan msg) - closeFlag := new(int32) - logger := logger{ - callback: config.Logger, - } - - atomic.StoreInt32(closeFlag, 0) - - go connectionStateMachine(config, closeFlag, channel, &logger) - - return &grpcClient{ - channel: channel, - closeFlag: closeFlag, + client := &grpcClient{ + channel: make(chan msg), + done: make(chan struct{}), once: new(sync.Once), - logger: &logger, + logger: &logger{callback: config.Logger}, perRPCCredentials: clientPerRPCCredentials(config), } + + go connectionStateMachine(config, client) + + return client } diff --git a/kurrentdb/impl.go b/kurrentdb/impl.go index 4c170eb..efdee04 100644 --- a/kurrentdb/impl.go +++ b/kurrentdb/impl.go @@ -8,7 +8,6 @@ import ( "strconv" "strings" "sync" - "sync/atomic" "time" "github.com/google/uuid" @@ -27,18 +26,34 @@ import ( type grpcClient struct { channel chan msg - closeFlag *int32 + done chan struct{} + closeErr error once *sync.Once logger *logger perRPCCredentials credentials.PerRPCCredentials } +func (client *grpcClient) closedError() error { + if client.closeErr != nil { + return client.closeErr + } + + return &Error{ + code: ErrorCodeConnectionClosed, + err: fmt.Errorf("connection is closed"), + } +} + +func contextError(ctx context.Context) error { + return &Error{ + code: errToCode(status.FromContextError(ctx.Err()).Err()), + err: ctx.Err(), + } +} + func (client *grpcClient) handleError(handle *connectionHandle, trailers metadata.MD, err error) error { if client.isClosed() { - return &Error{ - code: ErrorCodeConnectionClosed, - err: fmt.Errorf("connection is closed"), - } + return client.closedError() } if richErr := getDetail(err); richErr != nil { @@ -66,16 +81,12 @@ func (client *grpcClient) handleError(handle *connectionHandle, trailers metadat endpoint: &endpoint, } - if !client.isClosed() { - client.channel <- msg - client.logger.error("not leader exception, reconnecting to %v", endpoint) - return &Error{code: ErrorCodeNotLeader} + if err := client.send(context.Background(), msg); err != nil { + return err } - return &Error{ - code: ErrorCodeConnectionClosed, - err: fmt.Errorf("connection is closed"), - } + client.logger.error("not leader exception, reconnecting to %v", endpoint) + return &Error{code: ErrorCodeNotLeader} } } } @@ -88,40 +99,62 @@ func (client *grpcClient) handleError(handle *connectionHandle, trailers metadat client.logger.error("unexpected exception: %v", err) code := errToCode(err) - if code == ErrorUnavailable && !client.isClosed() { - client.channel <- reconnect{ + if code == ErrorUnavailable { + _ = client.send(context.Background(), reconnect{ correlation: handle.Id(), - } + }) } return &Error{code: code, err: err} } -func (client *grpcClient) getConnectionHandle() (*connectionHandle, error) { +func (client *grpcClient) send(ctx context.Context, m msg) error { + select { + case client.channel <- m: + return nil + case <-client.done: + return client.closedError() + case <-ctx.Done(): + return contextError(ctx) + } +} + +func (client *grpcClient) getConnectionHandle(ctx context.Context) (*connectionHandle, error) { if client.isClosed() { - return nil, &Error{ - code: ErrorCodeConnectionClosed, - err: fmt.Errorf("connection is closed"), - } + return nil, client.closedError() } msg := newGetConnectionMsg() - client.channel <- msg - - resp := <-msg.channel + if err := client.send(ctx, msg); err != nil { + return nil, err + } - return &resp, resp.err + select { + case resp := <-msg.channel: + return &resp, resp.err + case <-ctx.Done(): + return nil, contextError(ctx) + } } func (client *grpcClient) close() { + client.closeWith(nil) +} + +func (client *grpcClient) closeWith(err error) { client.once.Do(func() { - atomic.StoreInt32(client.closeFlag, 1) - close(client.channel) + client.closeErr = err + close(client.done) }) } func (client *grpcClient) isClosed() bool { - return atomic.LoadInt32(client.closeFlag) != 0 + select { + case <-client.done: + return true + default: + return false + } } type getConnection struct { @@ -132,7 +165,7 @@ func (msg getConnection) isMsg() {} func newGetConnectionMsg() getConnection { return getConnection{ - channel: make(chan connectionHandle), + channel: make(chan connectionHandle, 1), } } @@ -211,13 +244,16 @@ func newConnectionHandle(id uuid.UUID, serverInfo *serverInfo, connection *grpc. } } -func connectionStateMachine(config Configuration, closeFlag *int32, channel chan msg, logger *logger) { +func connectionStateMachine(config Configuration, client *grpcClient) { state := newConnectionState(config) + logger := client.logger for { - msg, ok := <-channel + var msg msg - if !ok { + select { + case msg = <-client.channel: + case <-client.done: if state.connection != nil { err := state.connection.Close() @@ -237,11 +273,11 @@ func connectionStateMachine(config Configuration, closeFlag *int32, channel chan conn, serverInfo, err := discoverNode(state.config, logger) if err != nil { - atomic.StoreInt32(closeFlag, 1) state.lastError = err resp := newErroredConnectionHandle(err) evt.channel <- resp close(evt.channel) + client.closeWith(err) return } diff --git a/kurrentdb/operations.go b/kurrentdb/operations.go index aa6262e..a083da5 100644 --- a/kurrentdb/operations.go +++ b/kurrentdb/operations.go @@ -1,5 +1,7 @@ package kurrentdb +import "context" + // ServerVersion Represents the version of a KurrentDB node. type ServerVersion struct { Major int @@ -9,7 +11,7 @@ type ServerVersion struct { // GetServerVersion Returns the version of the KurrentDB node to which the client is currently connected. func (client *Client) GetServerVersion() (*ServerVersion, error) { - handle, err := client.grpcClient.getConnectionHandle() + handle, err := client.grpcClient.getConnectionHandle(context.Background()) if err != nil { return nil, err } diff --git a/kurrentdb/persistent_subscription_http_client.go b/kurrentdb/persistent_subscription_http_client.go index 62cdef5..8f1216e 100644 --- a/kurrentdb/persistent_subscription_http_client.go +++ b/kurrentdb/persistent_subscription_http_client.go @@ -111,8 +111,8 @@ func (client *Client) httpRestartSubsystem(ctx context.Context, options RestartP return err } -func (client *Client) getBaseUrl() (string, error) { - handle, err := client.grpcClient.getConnectionHandle() +func (client *Client) getBaseUrl(ctx context.Context) (string, error) { + handle, err := client.grpcClient.getConnectionHandle(ctx) if err != nil { return "", err } @@ -145,7 +145,7 @@ type httpParams struct { } func (client *Client) httpExecute(ctx context.Context, method string, path string, auth *Credentials, params *httpParams) ([]byte, error) { - baseUrl, err := client.getBaseUrl() + baseUrl, err := client.getBaseUrl(ctx) if err != nil { return nil, fmt.Errorf("can't get a connection handle: %w", err) } diff --git a/kurrentdb/projection_client.go b/kurrentdb/projection_client.go index 4aeff51..a964da2 100644 --- a/kurrentdb/projection_client.go +++ b/kurrentdb/projection_client.go @@ -77,7 +77,7 @@ func (client *ProjectionClient) Create( return err } - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -119,7 +119,7 @@ func (client *ProjectionClient) Update( return err } - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -157,7 +157,7 @@ func (client *ProjectionClient) Delete( opts DeleteProjectionOptions, ) error { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -186,7 +186,7 @@ func (client *ProjectionClient) Enable( opts GenericProjectionOptions, ) error { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -229,7 +229,7 @@ func (client *ProjectionClient) disable( opts GenericProjectionOptions, ) error { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -256,7 +256,7 @@ func (client *ProjectionClient) Reset( opts ResetProjectionOptions, ) error { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -283,7 +283,7 @@ func (client *ProjectionClient) GetResult( opts GetResultProjectionOptions, ) (*structpb.Value, error) { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -314,7 +314,7 @@ func (client *ProjectionClient) GetState( opts GetStateProjectionOptions, ) (*structpb.Value, error) { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } @@ -344,7 +344,7 @@ func (client *ProjectionClient) RestartSubsystem( opts GenericProjectionOptions, ) error { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return err } @@ -450,7 +450,7 @@ func (client *ProjectionClient) listInternal( opts GenericProjectionOptions, ) ([]ProjectionStatus, error) { opts.setDefaults() - handle, err := client.inner.grpcClient.getConnectionHandle() + handle, err := client.inner.grpcClient.getConnectionHandle(context) if err != nil { return nil, err } From 43a447e25f1b26c8db42d7638f9a413c3b80e2d6 Mon Sep 17 00:00:00 2001 From: w1am <33353798+w1am@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:50:34 +0400 Subject: [PATCH 2/5] Fix CI skipping the kurrentdb package unit tests --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fc44def..69763ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -59,8 +59,8 @@ jobs: username: ${{ secrets.CLOUDSMITH_CICD_USER }} password: ${{ secrets.CLOUDSMITH_CICD_TOKEN }} - - name: Misc tests - run: go test --count=1 -v ./kurrentdb -run TestMisc + - name: Unit tests + run: go test --count=1 -v ./kurrentdb - name: Start KurrentDB run: make start-kurrentdb From 7fa6baf01c9ed981267b8289d271adcb486a49d5 Mon Sep 17 00:00:00 2001 From: w1am <33353798+w1am@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:51:55 +0400 Subject: [PATCH 3/5] Fix CI skipping the TestMisc unit suites --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 69763ea..70b65af 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,7 +60,9 @@ jobs: password: ${{ secrets.CLOUDSMITH_CICD_TOKEN }} - name: Unit tests - run: go test --count=1 -v ./kurrentdb + run: | + go test --count=1 -v ./kurrentdb + go test --count=1 -v ./test -run TestMisc - name: Start KurrentDB run: make start-kurrentdb From ba5e8b726f03db78ad4997503941c08a1f83f13c Mon Sep 17 00:00:00 2001 From: w1am <33353798+w1am@users.noreply.github.com> Date: Tue, 3 Nov 2026 12:23:59 +0400 Subject: [PATCH 4/5] Fix calls blocking past Close while discovery is in progress --- kurrentdb/connection_test.go | 29 +++++++++++++++++++++++++++++ kurrentdb/impl.go | 2 ++ 2 files changed, 31 insertions(+) diff --git a/kurrentdb/connection_test.go b/kurrentdb/connection_test.go index 3f17470..99101a4 100644 --- a/kurrentdb/connection_test.go +++ b/kurrentdb/connection_test.go @@ -50,3 +50,32 @@ func TestDiscoveryFailureReleasesConcurrentCallers(t *testing.T) { require.NoError(t, client.Close()) } } + +func TestCloseReleasesCallerDuringDiscovery(t *testing.T) { + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(t, err) + defer listener.Close() + + config, err := ParseConnectionString("kurrentdb://" + listener.Addr().String() + "?tls=false&maxDiscoverAttempts=10&gossipTimeout=5") + require.NoError(t, err) + + client, err := NewClient(config) + require.NoError(t, err) + + errs := make(chan error, 1) + go func() { + _, err := client.ReadStream(context.Background(), "repro", ReadStreamOptions{}, 1) + errs <- err + }() + + time.Sleep(100 * time.Millisecond) + require.NoError(t, client.Close()) + + select { + case err := <-errs: + kurrentErr, _ := FromError(err) + require.Equal(t, ErrorCodeConnectionClosed, kurrentErr.Code()) + case <-time.After(time.Second): + t.Fatal("caller still blocked after Close") + } +} diff --git a/kurrentdb/impl.go b/kurrentdb/impl.go index efdee04..708a77b 100644 --- a/kurrentdb/impl.go +++ b/kurrentdb/impl.go @@ -132,6 +132,8 @@ func (client *grpcClient) getConnectionHandle(ctx context.Context) (*connectionH select { case resp := <-msg.channel: return &resp, resp.err + case <-client.done: + return nil, client.closedError() case <-ctx.Done(): return nil, contextError(ctx) } From cfa42ad8a6a9a27b66469ca4a4842e9aae6d05c5 Mon Sep 17 00:00:00 2001 From: w1am <33353798+w1am@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:19:23 +0400 Subject: [PATCH 5/5] Fix failed discovery dropping ErrorCodeConnectionClosed from later calls --- kurrentdb/impl.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kurrentdb/impl.go b/kurrentdb/impl.go index 708a77b..cfb262d 100644 --- a/kurrentdb/impl.go +++ b/kurrentdb/impl.go @@ -34,13 +34,14 @@ type grpcClient struct { } func (client *grpcClient) closedError() error { - if client.closeErr != nil { - return client.closeErr + err := client.closeErr + if err == nil { + err = fmt.Errorf("connection is closed") } return &Error{ code: ErrorCodeConnectionClosed, - err: fmt.Errorf("connection is closed"), + err: err, } }