Skip to content

Commit 414262b

Browse files
receive: Recreate Cap’n Proto client when bootstrap fails (port of thanos-io#8491) (thanos-io#474)
1 parent 2dd41a7 commit 414262b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/receive/writecapnp/client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,20 @@ func (r *RemoteWriteClient) connect(ctx context.Context) error {
146146
r.codec = codec
147147

148148
rpcConn := rpc.NewConn(rpc.NewTransport(r.codec), nil)
149-
r.writer = Writer(rpcConn.Bootstrap(ctx))
149+
writer := Writer(rpcConn.Bootstrap(ctx))
150+
// Ensure the bootstrap resolves; if it fails, tear down and let caller retry.
151+
if err := writer.Resolve(ctx); err != nil {
152+
level.Warn(r.logger).Log("msg", "capnp bootstrap failed, recreating client", "err", err)
153+
_ = rpcConn.Close()
154+
// Close the codec and reset so next attempt will fully recreate the client.
155+
codec := r.codec
156+
r.codec = nil
157+
go func() {
158+
runutil.CloseWithLogOnErr(r.logger, codec, "capnp codec")
159+
}()
160+
return errors.Wrap(err, "capnp bootstrap failed")
161+
}
162+
r.writer = writer
150163
return nil
151164
}
152165

0 commit comments

Comments
 (0)