File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 77 "encoding/json"
88 "fmt"
99 "os"
10+ "time"
1011
1112 "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1213 "github.com/spf13/cobra"
@@ -26,6 +27,10 @@ import (
2627 "github.com/conductorone/baton-sdk/pkg/uotel"
2728)
2829
30+ const (
31+ otelShutdownTimeout = 5 * time .Second
32+ )
33+
2934type ContrainstSetter func (* cobra.Command , field.Configuration ) error
3035
3136func MakeMainCommand [T field.Configurable ](
@@ -64,7 +69,9 @@ func MakeMainCommand[T field.Configurable](
6469 if otelShutdown == nil {
6570 return
6671 }
67- err := otelShutdown (context .Background ())
72+ shutdownCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (otelShutdownTimeout ))
73+ defer cancel ()
74+ err := otelShutdown (shutdownCtx )
6875 if err != nil {
6976 zap .L ().Error ("error shutting down otel" , zap .Error (err ))
7077 }
@@ -332,7 +339,12 @@ func MakeGRPCServerCommand[T field.Configurable](
332339 return err
333340 }
334341 defer func () {
335- err := otelShutdown (context .Background ())
342+ if otelShutdown == nil {
343+ return
344+ }
345+ shutdownCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (otelShutdownTimeout ))
346+ defer cancel ()
347+ err := otelShutdown (shutdownCtx )
336348 if err != nil {
337349 zap .L ().Error ("error shutting down otel" , zap .Error (err ))
338350 }
Original file line number Diff line number Diff line change 88 "encoding/json"
99 "fmt"
1010 "os"
11+ "time"
1112
1213 aws_lambda "github.com/aws/aws-lambda-go/lambda"
1314 "github.com/conductorone/baton-sdk/pkg/crypto/providers/jwk"
@@ -78,7 +79,12 @@ func OptionallyAddLambdaCommand[T field.Configurable](
7879 return err
7980 }
8081 defer func () {
81- err := otelShutdown (context .Background ())
82+ if otelShutdown == nil {
83+ return
84+ }
85+ shutdownCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (otelShutdownTimeout ))
86+ defer cancel ()
87+ err := otelShutdown (shutdownCtx )
8288 if err != nil {
8389 zap .L ().Error ("error shutting down otel" , zap .Error (err ))
8490 }
@@ -178,5 +184,4 @@ func OptionallyAddLambdaCommand[T field.Configurable](
178184 return nil
179185 }
180186 return nil
181-
182187}
You can’t perform that action at this time.
0 commit comments