Skip to content

Commit

Permalink
Move binary client timeout to Go
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Mar 19, 2024
1 parent ecd6db9 commit 0f73121
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion js/src/binary-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ export class DateiLagerBinaryClient {
? {
update: options.timeout,
rebuild: options.timeout,
gc: options.timeout,
}
: {
update: 0,
rebuild: 0,
gc: 0,
...options.timeout,
},
tracing: options.tracing ?? false,
Expand Down Expand Up @@ -365,6 +367,9 @@ export class DateiLagerBinaryClient {
baseArgs.push("--headless-host", this._options.headlessHost);
}

const timeout = options?.timeout ?? this._options.timeout[method];
baseArgs.push("--timeout", String(timeout));

if (this._options.tracing) {
const carrier = {};
propagation.inject(context.active(), carrier);
Expand All @@ -375,7 +380,6 @@ export class DateiLagerBinaryClient {
const subprocess = execa(this._options.command, baseArgs.concat(args), {
cwd,
cleanup: false, // don't terminate this subprocess process eagerly when the parent process is terminated, which is execa's default behaviour. we use graceful shutdown gadget-side to give running operations a chance to complete, and we don't want to terminate them prematurely
timeout: options?.timeout ?? this._options.timeout[method],
env: { DL_TOKEN: await this._options.token() },
});

Expand Down
13 changes: 9 additions & 4 deletions pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewClientCommand() *cobra.Command {
otelContext string
host string
port uint16
timeout uint16
headlessHost string
)

Expand All @@ -57,6 +58,12 @@ func NewClientCommand() *cobra.Command {

ctx := cmd.Context()

if timeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(cmd.Context(), time.Duration(timeout)*time.Second)
defer cancel()
}

if tracing {
shutdownTelemetry = telemetry.Init(ctx, telemetry.Client)
}
Expand Down Expand Up @@ -99,6 +106,7 @@ func NewClientCommand() *cobra.Command {
flags.StringVar(&otelContext, "otel-context", "", "Open Telemetry context")
flags.StringVar(&host, "host", "", "GRPC server hostname")
flags.Uint16Var(&port, "port", 5051, "GRPC server port")
flags.Uint16Var(&timeout, "timeout", 5051, "GRPC client timeout")
flags.StringVar(&headlessHost, "headless-host", "", "Alternative headless hostname to use for round robin connections")

cmd.AddCommand(NewCmdGet())
Expand All @@ -115,11 +123,8 @@ func NewClientCommand() *cobra.Command {
}

func ClientExecute() {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Second)
defer cancel()

ctx := context.Background()
cmd := NewClientCommand()

err := cmd.ExecuteContext(ctx)

client := client.FromContext(cmd.Context())
Expand Down

0 comments on commit 0f73121

Please sign in to comment.