@@ -3,6 +3,7 @@ package state
33import (
44 "context"
55 "fmt"
6+ "time"
67
78 "github.com/ifuryst/lol"
89 "github.com/amoylab/unla/internal/common/cnst"
@@ -244,7 +245,11 @@ func startMCPServer(ctx context.Context, logger *zap.Logger, prefix string, mcpS
244245 return
245246 }
246247
247- if err := transport .Start (ctx , template .NewContext ()); err != nil {
248+ // Create a new context to avoid being canceled when the main context is canceled during shutdown
249+ startCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
250+ defer cancel ()
251+
252+ if err := transport .Start (startCtx , template .NewContext ()); err != nil {
248253 logger .Error ("failed to start server for preinstall" ,
249254 zap .String ("prefix" , prefix ),
250255 zap .String ("command" , mcpServer .Command ),
@@ -258,7 +263,7 @@ func startMCPServer(ctx context.Context, logger *zap.Logger, prefix string, mcpS
258263
259264 if needStop {
260265 // Stop the server after successful start
261- if err := transport .Stop (ctx ); err != nil {
266+ if err := transport .Stop (startCtx ); err != nil {
262267 logger .Error ("failed to stop server for preinstall" ,
263268 zap .String ("prefix" , prefix ),
264269 zap .String ("command" , mcpServer .Command ),
0 commit comments