Skip to content

Commit 89e307e

Browse files
committed
fix: etcd client leak in the (legacy) Upgrade API
This doesn't affect new upgrade API. There were two leaks in the validate path, usually they are harmless, as the Upgrade triggers a reboot, so a couple of leaking clients doesn't matter, but if they API is called repeatedly (and it fails to upgrade), the leak accumulates until `etcd` container runs out of file descriptor, eventually preventing new connections to `etcd` from being established. Also put the etcd pre-checks under the `!preserve` condition (means the API requests wipe). The wipe behavior was disabled by default for a long time, and all etcd pre-checks only make sense if the wipe is called, otherwise upgrade doesn't affect etcd membership in any way. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 476c4d0 commit 89e307e

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,14 @@ func (s *Server) Upgrade(ctx context.Context, in *machine.UpgradeRequest) (*mach
531531
return nil, fmt.Errorf("error validating installer image %q: %w", in.GetImage(), err)
532532
}
533533

534-
if !inMaintenance && s.Controller.Runtime().Config().Machine().Type() != machinetype.TypeWorker && !in.GetForce() {
534+
if !inMaintenance && s.Controller.Runtime().Config().Machine().Type() != machinetype.TypeWorker && !in.GetForce() && !in.GetPreserve() {
535535
etcdClient, err := etcd.NewClientFromControlPlaneIPs(ctx, s.Controller.Runtime().State().V1Alpha2().Resources())
536536
if err != nil {
537537
return nil, fmt.Errorf("failed to create etcd client: %w", err)
538538
}
539539

540+
defer etcdClient.Close() //nolint:errcheck
541+
540542
// acquire the upgrade mutex
541543
unlocker, err := tryLockUpgradeMutex(ctx, etcdClient)
542544
if err != nil {

internal/pkg/etcd/etcd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func validateMemberHealth(ctx context.Context, memberURIs []string) (err error)
145145
return fmt.Errorf("failed to create client to member: %w", err)
146146
}
147147

148+
defer c.Close() //nolint:errcheck
149+
148150
return c.ValidateQuorum(ctx)
149151
}
150152

0 commit comments

Comments
 (0)