Skip to content

Commit

Permalink
Fix 10 second etcd-snapshot request timeout
Browse files Browse the repository at this point in the history
The default clientaccess request timeout is too short. Wait longer by default, and add the s3 timeout if s3 is enabled.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit d3b6054)
  • Loading branch information
brandond committed Apr 22, 2024
1 parent 48b30e2 commit 8eed41d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/cli/etcdsnapshot/etcd_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package etcdsnapshot

import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -26,6 +27,8 @@ import (
"k8s.io/cli-runtime/pkg/printers"
)

var timeout = 2 * time.Minute

// commandSetup setups up common things needed
// for each etcd command.
func commandSetup(app *cli.Context, cfg *cmds.Server) (*etcd.SnapshotRequest, *clientaccess.Info, error) {
Expand Down Expand Up @@ -58,6 +61,8 @@ func commandSetup(app *cli.Context, cfg *cmds.Server) (*etcd.SnapshotRequest, *c
sr.S3.SecretKey = cfg.EtcdS3SecretKey
sr.S3.SkipSSLVerify = cfg.EtcdS3SkipSSLVerify
sr.S3.Timeout = metav1.Duration{Duration: cfg.EtcdS3Timeout}
// extend request timeout to allow the S3 operation to complete
timeout += cfg.EtcdS3Timeout
}

dataDir, err := server.ResolveDataDir(cfg.DataDir)
Expand All @@ -78,6 +83,11 @@ func commandSetup(app *cli.Context, cfg *cmds.Server) (*etcd.SnapshotRequest, *c
}

func wrapServerError(err error) error {
if errors.Is(err, context.DeadlineExceeded) {
// if the request timed out the server log likely won't contain anything useful,
// since the operation may have actualy succeeded despite the client timing out the request.
return err
}
return errors.Wrap(err, "see server log for details")
}

Expand Down Expand Up @@ -110,7 +120,7 @@ func save(app *cli.Context, cfg *cmds.Server) error {
if err != nil {
return err
}
r, err := info.Post("/db/snapshot", b)
r, err := info.Post("/db/snapshot", b, clientaccess.WithTimeout(timeout))
if err != nil {
return wrapServerError(err)
}
Expand Down Expand Up @@ -151,7 +161,7 @@ func delete(app *cli.Context, cfg *cmds.Server) error {
if err != nil {
return err
}
r, err := info.Post("/db/snapshot", b)
r, err := info.Post("/db/snapshot", b, clientaccess.WithTimeout(timeout))
if err != nil {
return wrapServerError(err)
}
Expand Down Expand Up @@ -206,7 +216,7 @@ func list(app *cli.Context, cfg *cmds.Server) error {
if err != nil {
return err
}
r, err := info.Post("/db/snapshot", b)
r, err := info.Post("/db/snapshot", b, clientaccess.WithTimeout(timeout))
if err != nil {
return wrapServerError(err)
}
Expand Down Expand Up @@ -269,7 +279,7 @@ func prune(app *cli.Context, cfg *cmds.Server) error {
if err != nil {
return err
}
r, err := info.Post("/db/snapshot", b)
r, err := info.Post("/db/snapshot", b, clientaccess.WithTimeout(timeout))
if err != nil {
return wrapServerError(err)
}
Expand Down

0 comments on commit 8eed41d

Please sign in to comment.