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

fix: invalidated config should retain error #1068

Merged
merged 8 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion proxy/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (c *Client) selectDialer() func(context.Context, string, string) (net.Conn,
}
}

func (c *Client) invalidateCfg(cfg *tls.Config, instance string) {
func (c *Client) invalidateCfg(cfg *tls.Config, instance string, err error) {
c.cacheL.RLock()
e := c.cfgCache[instance]
c.cacheL.RUnlock()
Expand All @@ -541,6 +541,7 @@ func (c *Client) invalidateCfg(cfg *tls.Config, instance string) {
return
}
c.cfgCache[instance] = cacheEntry{
err: err,
done: e.done,
lastRefreshed: e.lastRefreshed,
}
Expand Down
22 changes: 22 additions & 0 deletions proxy/proxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,29 @@ func TestClientHandshakeCanceled(t *testing.T) {
_, err := c.DialContext(ctx, instance)
validateError(t, err)
})
})

t.Run("when liveness check is called on invalidated config", func(t *testing.T) {
withTestHarness(t, func(port int) {
c := newClient(port)

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

_, err := c.DialContext(ctx, instance)
if err == nil {
t.Fatal("expected DialContext to fail, got no error")
}

invalid := c.InvalidInstances()
if gotLen := len(invalid); gotLen != 1 {
t.Fatalf("invalid instance want = 1, got = %v", gotLen)
}
got := invalid[0]
if got.err == nil {
t.Fatal("want invalid instance error, got nil")
}
})
})

// Makes it to Handshake.
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy/connect_tls_117.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *Client) connectTLS(
// this file is conditionally compiled on only Go versions >= 1.17.
if err := ret.HandshakeContext(ctx); err != nil {
_ = ret.Close()
c.invalidateCfg(cfg, instance)
c.invalidateCfg(cfg, instance, err)
enocom marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}
return ret, nil
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy/connect_tls_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *Client) connectTLS(
ret := tls.Client(conn, cfg)
if err := ret.Handshake(); err != nil {
_ = ret.Close()
c.invalidateCfg(cfg, instance)
c.invalidateCfg(cfg, instance, err)
return nil, err
}
return ret, nil
Expand Down