Skip to content

Commit

Permalink
Use go 1.21
Browse files Browse the repository at this point in the history
This allows us to use context.WithoutCancel and there's no expected incompatible breaking changes.
  • Loading branch information
sfc-gh-srhodes committed Oct 9, 2023
1 parent 6e6fa86 commit a39506a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Snowflake-Labs/sansshell

go 1.19
go 1.21

require (
github.com/coreos/go-systemd/v22 v22.5.0
Expand Down
18 changes: 1 addition & 17 deletions services/fdb/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/google/subcommands"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -3709,24 +3708,9 @@ func (r *fdbMoveDataWaitCmd) printCommandOutput(state *util.ExecuteState, idx in
}
}

// This context detachment is temporary until we use go1.21 and context.WithoutCancel is available.
type noCancel struct {
ctx context.Context
}

func (c noCancel) Deadline() (time.Time, bool) { return time.Time{}, false }
func (c noCancel) Done() <-chan struct{} { return nil }
func (c noCancel) Err() error { return nil }
func (c noCancel) Value(key interface{}) interface{} { return c.ctx.Value(key) }

// WithoutCancel returns a context that is never canceled.
func WithoutCancel(ctx context.Context) context.Context {
return noCancel{ctx: ctx}
}

func (r *fdbMoveDataWaitCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
// Ignore the parent context timeout because we don't want to time out here.
ctx = WithoutCancel(ctx)
ctx = context.WithoutCancel(ctx)
state := args[0].(*util.ExecuteState)
c := pb.NewFDBMoveClientProxy(state.Conn)

Expand Down
18 changes: 1 addition & 17 deletions services/httpoverrpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/google/subcommands"

Expand Down Expand Up @@ -86,21 +85,6 @@ func (p *proxyCmd) SetFlags(f *flag.FlagSet) {
f.BoolVar(&p.allowAnyHost, "allow-any-host", false, "Serve data regardless of the Host in HTTP requests instead of only allowing localhost and IPs. False by default to prevent DNS rebinding attacks.")
}

// This context detachment is temporary until we use go1.21 and context.WithoutCancel is available.
type noCancel struct {
ctx context.Context
}

func (c noCancel) Deadline() (time.Time, bool) { return time.Time{}, false }
func (c noCancel) Done() <-chan struct{} { return nil }
func (c noCancel) Err() error { return nil }
func (c noCancel) Value(key interface{}) interface{} { return c.ctx.Value(key) }

// WithoutCancel returns a context that is never canceled.
func WithoutCancel(ctx context.Context) context.Context {
return noCancel{ctx: ctx}
}

func sendError(resp http.ResponseWriter, code int, err error) {
resp.WriteHeader(code)
if _, err := resp.Write([]byte(err.Error())); err != nil {
Expand All @@ -114,7 +98,7 @@ func validatePort(port int) bool {

func (p *proxyCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
// Ignore the parent context timeout because we don't want to time out here.
ctx = WithoutCancel(ctx)
ctx = context.WithoutCancel(ctx)
state := args[0].(*util.ExecuteState)
if f.NArg() != 1 {
fmt.Fprintln(os.Stderr, "Please specify a port to proxy.")
Expand Down

0 comments on commit a39506a

Please sign in to comment.