Skip to content

Commit 7fcc6eb

Browse files
authored
Add support for configurable application start timeout (#30)
Integrate `StartTimeout` across configurations and components, enabling a customizable duration for application startup, and update relevant CLI flags and documentation.
1 parent 133a407 commit 7fcc6eb

6 files changed

Lines changed: 37 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ GLOBAL OPTIONS:
7575

7676
worker
7777

78-
--worker-send-timeout value the timeout for a single message send operation. (default: 30s) [$FUNCTION_WORKER_SEND_TIMEOUT]
79-
--worker-stop-timeout value the duration to wait for a worker process to stop. (default: 5s) [$FUNCTION_WORKER_STOP_TIMEOUT]
78+
--worker-send-timeout value the timeout for a single message send operation. (default: 30s) [$FUNCTION_WORKER_SEND_TIMEOUT]
79+
--worker-start-timeout value the duration to wait for the application to start (worker process boot + first successful RPC dial). (default: 15s) [$FUNCTION_WORKER_START_TIMEOUT]
80+
--worker-stop-timeout value the duration to wait for a worker process to stop. (default: 5s) [$FUNCTION_WORKER_STOP_TIMEOUT]
8081
```
8182

8283
## Evaluation Runtime Interface

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func New(ctx *cli.Context) (*shell.Shell, error) {
3232
runtime.Module(config.Runtime),
3333
)
3434

35-
return shell.New(log, appModule), nil
35+
return shell.New(log, config.StartTimeout, appModule), nil
3636
}

cmd/root.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ functions on arbitrary, serverless platforms.`
104104
Category: "worker",
105105
EnvVars: []string{"FUNCTION_WORKER_SEND_TIMEOUT"},
106106
},
107+
&cli.DurationFlag{
108+
Name: "worker-start-timeout",
109+
Usage: "the duration to wait for the application to start (worker process boot + first successful RPC dial).",
110+
Value: 15 * time.Second,
111+
Category: "worker",
112+
EnvVars: []string{"FUNCTION_WORKER_START_TIMEOUT"},
113+
},
107114
&cli.StringFlag{
108115
Name: "rpc-transport",
109116
Aliases: []string{"t"},
@@ -331,6 +338,7 @@ func parseRootConfig(ctx *cli.Context) (config.Config, error) {
331338
"rpc-transport-tcp-address": "runtime.io.rpc.tcp.address",
332339
"worker-send-timeout": "runtime.send.timeout",
333340
"worker-stop-timeout": "runtime.stop.timeout",
341+
"worker-start-timeout": "start_timeout",
334342
// sandbox
335343
"sandbox": "runtime.sandbox.enabled",
336344
"sandbox-nsjail-path": "runtime.sandbox.nsjail_path",

config/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package config
22

3-
import "github.com/lambda-feedback/shimmy/runtime"
3+
import (
4+
"time"
5+
6+
"github.com/lambda-feedback/shimmy/runtime"
7+
)
48

59
type MessageEncoding string
610

@@ -25,4 +29,7 @@ type Config struct {
2529

2630
// Auth is the authentication configuration
2731
Auth AuthConfig `conf:"auth"`
32+
33+
// StartTimeout is the duration to wait for the application to start.
34+
StartTimeout time.Duration `conf:"start_timeout"`
2835
}

internal/execution/supervisor/adapter_rpc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ func (a *rpcAdapter) dialRpcWithRetry(
191191
) error {
192192
var err error
193193
for i := 0; ; i++ {
194-
if client, err := a.dialRpc(ctx, a.config); err == nil {
194+
var client *rpc.Client
195+
client, err = a.dialRpc(ctx, a.config)
196+
if err == nil {
195197
a.rpcClient = client
196198
return nil
197199
}

internal/shell/shell.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ package shell
22

33
import (
44
"context"
5+
"time"
56

67
"go.uber.org/fx"
78
"go.uber.org/fx/fxevent"
89
"go.uber.org/zap"
910
)
1011

1112
type Shell struct {
12-
log *zap.Logger
13-
fxApp *fx.App
14-
options []fx.Option
13+
log *zap.Logger
14+
fxApp *fx.App
15+
startTimeout time.Duration
16+
options []fx.Option
1517
}
1618

17-
func New(log *zap.Logger, options ...fx.Option) *Shell {
19+
func New(log *zap.Logger, startTimeout time.Duration, options ...fx.Option) *Shell {
1820
return &Shell{
19-
log: log,
20-
options: options,
21+
log: log,
22+
startTimeout: startTimeout,
23+
options: options,
2124
}
2225
}
2326

@@ -80,10 +83,13 @@ func (s *Shell) createFxApp(ctx context.Context, options ...fx.Option) *fx.App {
8083
return &fxevent.ZapLogger{Logger: s.log.Named("fx")}
8184
}),
8285

83-
// 5. provide user-provided options
86+
// 5. configure the application start timeout
87+
fx.StartTimeout(s.startTimeout),
88+
89+
// 6. provide user-provided options
8490
fx.Options(s.options...),
8591

86-
// 5. provide user-provided run options
92+
// 7. provide user-provided run options
8793
fx.Options(options...),
8894
)
8995
}

0 commit comments

Comments
 (0)