diff --git a/flytestdlib/profutils/server.go b/flytestdlib/profutils/server.go index 50485b7ea3..a1b5baf5ea 100644 --- a/flytestdlib/profutils/server.go +++ b/flytestdlib/profutils/server.go @@ -100,13 +100,14 @@ func StartProfilingServer(ctx context.Context, pprofPort int) error { Addr: fmt.Sprintf(":%d", pprofPort), } - e := srv.ListenAndServe() - if e != nil { - logger.Errorf(ctx, "Failed to start profiling server. Error: %v", e) - return fmt.Errorf("failed to start profiling server, %s", e) - } + go func() { + e := srv.ListenAndServe() + if e != nil { + logger.Errorf(ctx, "Failed to start profiling server. Error: %v", e) + } + }() - return nil + return srv.Shutdown(ctx) } func configureGlobalHTTPHandler(handlers map[string]http.Handler) error {