mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
feat(mcphost): optimize shutdown logging to avoid false error messages
- Add identification for normal shutdown pipe errors in startStdioLog - Optimize stdio log error handling logic to distinguish between normal shutdown and actual errors - Add proper handling for SIGTERM (exit status 143) in isSignalError function - Add debug logging for MCP config loading process - Ensure clean shutdown without confusing error messages
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506021152
|
v5.0.0-beta-2506031321
|
||||||
|
|||||||
+5
-1
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -93,6 +95,7 @@ func (w ServerConfigWrapper) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
// LoadMCPConfig loads the MCP configuration from the specified path or default location
|
// LoadMCPConfig loads the MCP configuration from the specified path or default location
|
||||||
func LoadMCPConfig(configPath string) (*MCPConfig, error) {
|
func LoadMCPConfig(configPath string) (*MCPConfig, error) {
|
||||||
|
log.Debug().Str("configPath", configPath).Msg("Loading MCP config")
|
||||||
if configPath == "" {
|
if configPath == "" {
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -122,6 +125,7 @@ func LoadMCPConfig(configPath string) (*MCPConfig, error) {
|
|||||||
return nil, fmt.Errorf("error parsing config file: %w", err)
|
return nil, fmt.Errorf("error parsing config file: %w", err)
|
||||||
}
|
}
|
||||||
config.ConfigPath = configPath
|
config.ConfigPath = configPath
|
||||||
|
log.Debug().Str("configPath", configPath).
|
||||||
|
Interface("config", config).Msg("Loaded MCP config")
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -228,6 +228,7 @@ func isSignalError(err error) bool {
|
|||||||
strings.Contains(errStr, "signal: terminated") ||
|
strings.Contains(errStr, "signal: terminated") ||
|
||||||
strings.Contains(errStr, "exit status 120") ||
|
strings.Contains(errStr, "exit status 120") ||
|
||||||
strings.Contains(errStr, "exit status 130") ||
|
strings.Contains(errStr, "exit status 130") ||
|
||||||
|
strings.Contains(errStr, "exit status 143") || // SIGTERM (15)
|
||||||
strings.Contains(errStr, "broken pipe") ||
|
strings.Contains(errStr, "broken pipe") ||
|
||||||
strings.Contains(errStr, "connection reset")
|
strings.Contains(errStr, "connection reset")
|
||||||
}
|
}
|
||||||
@@ -472,7 +473,12 @@ func startStdioLog(stderr io.Reader, serverName string, ctx context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
// Scanner finished or encountered error
|
// Scanner finished or encountered error
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Debug().Str("server", serverName).Err(err).Msg("stdio log scanner error")
|
// Check if it's a normal shutdown error (pipe closed)
|
||||||
|
if isNormalShutdownError(err) {
|
||||||
|
log.Debug().Str("server", serverName).Msg("stdio log stopped due to normal shutdown")
|
||||||
|
} else {
|
||||||
|
log.Debug().Str("server", serverName).Err(err).Msg("stdio log scanner error")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -481,6 +487,16 @@ func startStdioLog(stderr io.Reader, serverName string, ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isNormalShutdownError checks if the error is caused by normal shutdown (pipe closed)
|
||||||
|
func isNormalShutdownError(err error) bool {
|
||||||
|
errStr := err.Error()
|
||||||
|
// Common pipe closed error patterns during normal shutdown
|
||||||
|
return strings.Contains(errStr, "file already closed") ||
|
||||||
|
strings.Contains(errStr, "broken pipe") ||
|
||||||
|
strings.Contains(errStr, "use of closed file") ||
|
||||||
|
strings.Contains(errStr, "read/write on closed pipe")
|
||||||
|
}
|
||||||
|
|
||||||
// prepareClientInitRequest creates a standard initialization request
|
// prepareClientInitRequest creates a standard initialization request
|
||||||
func prepareClientInitRequest() mcp.InitializeRequest {
|
func prepareClientInitRequest() mcp.InitializeRequest {
|
||||||
return mcp.InitializeRequest{
|
return mcp.InitializeRequest{
|
||||||
|
|||||||
Reference in New Issue
Block a user