6
6
"context"
7
7
log "github.com/sirupsen/logrus"
8
8
"go.amzn.com/lambda/rapidcore"
9
- "net/http"
10
- _ "net/http/pprof"
11
9
"os"
12
10
"runtime/debug"
13
11
"strconv"
@@ -27,7 +25,7 @@ type LsOpts struct {
27
25
InitLogLevel string
28
26
EdgePort string
29
27
EnableXRayTelemetry string
30
- PostInvokeWaitMS string
28
+ PostInvokeWaitMS string
31
29
}
32
30
33
31
func GetEnvOrDie (env string ) string {
@@ -55,7 +53,7 @@ func InitLsOpts() *LsOpts {
55
53
EnableDnsServer : os .Getenv ("LOCALSTACK_ENABLE_DNS_SERVER" ),
56
54
EnableXRayTelemetry : os .Getenv ("LOCALSTACK_ENABLE_XRAY_TELEMETRY" ),
57
55
LocalstackIP : os .Getenv ("LOCALSTACK_HOSTNAME" ),
58
- PostInvokeWaitMS : os .Getenv ("LOCALSTACK_POST_INVOKE_WAIT_MS" ),
56
+ PostInvokeWaitMS : os .Getenv ("LOCALSTACK_POST_INVOKE_WAIT_MS" ),
59
57
}
60
58
}
61
59
@@ -113,7 +111,7 @@ func main() {
113
111
114
112
// download code archive if env variable is set
115
113
if err := DownloadCodeArchives (lsOpts .CodeArchives ); err != nil {
116
- log .Fatal ("Failed to download code archives" )
114
+ log .Fatal ("Failed to download code archives: " + err . Error () )
117
115
}
118
116
119
117
// parse CLI args
@@ -168,6 +166,10 @@ func main() {
168
166
if len (handler ) > 0 {
169
167
sandbox .SetHandler (handler )
170
168
}
169
+ exitChan := make (chan struct {})
170
+ sandbox .AddShutdownFunc (func () {
171
+ exitChan <- struct {}{}
172
+ })
171
173
172
174
// initialize all flows and start runtime API
173
175
go sandbox .Create ()
@@ -183,10 +185,5 @@ func main() {
183
185
// start runtime init
184
186
go InitHandler (sandbox , GetEnvOrDie ("AWS_LAMBDA_FUNCTION_VERSION" ), int64 (invokeTimeoutSeconds )) // TODO: replace this with a custom init
185
187
186
- // TODO: make the tracing server optional
187
- // start blocking with the tracing server
188
- err = http .ListenAndServe ("0.0.0.0:" + lsOpts .InitTracingPort , http .DefaultServeMux )
189
- if err != nil {
190
- log .Fatal ("Failed to start debug server" )
191
- }
188
+ <- exitChan
192
189
}
0 commit comments