66 "context"
77 log "github.com/sirupsen/logrus"
88 "go.amzn.com/lambda/rapidcore"
9- "net/http"
10- _ "net/http/pprof"
119 "os"
1210 "runtime/debug"
1311 "strconv"
@@ -27,7 +25,7 @@ type LsOpts struct {
2725 InitLogLevel string
2826 EdgePort string
2927 EnableXRayTelemetry string
30- PostInvokeWaitMS string
28+ PostInvokeWaitMS string
3129}
3230
3331func GetEnvOrDie (env string ) string {
@@ -55,7 +53,7 @@ func InitLsOpts() *LsOpts {
5553 EnableDnsServer : os .Getenv ("LOCALSTACK_ENABLE_DNS_SERVER" ),
5654 EnableXRayTelemetry : os .Getenv ("LOCALSTACK_ENABLE_XRAY_TELEMETRY" ),
5755 LocalstackIP : os .Getenv ("LOCALSTACK_HOSTNAME" ),
58- PostInvokeWaitMS : os .Getenv ("LOCALSTACK_POST_INVOKE_WAIT_MS" ),
56+ PostInvokeWaitMS : os .Getenv ("LOCALSTACK_POST_INVOKE_WAIT_MS" ),
5957 }
6058}
6159
@@ -113,7 +111,7 @@ func main() {
113111
114112 // download code archive if env variable is set
115113 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 () )
117115 }
118116
119117 // parse CLI args
@@ -168,6 +166,10 @@ func main() {
168166 if len (handler ) > 0 {
169167 sandbox .SetHandler (handler )
170168 }
169+ exitChan := make (chan struct {})
170+ sandbox .AddShutdownFunc (func () {
171+ exitChan <- struct {}{}
172+ })
171173
172174 // initialize all flows and start runtime API
173175 go sandbox .Create ()
@@ -183,10 +185,5 @@ func main() {
183185 // start runtime init
184186 go InitHandler (sandbox , GetEnvOrDie ("AWS_LAMBDA_FUNCTION_VERSION" ), int64 (invokeTimeoutSeconds )) // TODO: replace this with a custom init
185187
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
192189}
0 commit comments