mirror of https://github.com/Wox-launcher/Wox
feat(chat): Delay MCP servers reload to avoid websocket initialization race condition
* Introduced a delay before reloading MCP servers to ensure the websocket server is ready. * This change prevents potential race conditions during initialization.
This commit is contained in:
parent
c1c6ced55d
commit
1657a44f19
|
@ -278,7 +278,11 @@ func (r *AIChatPlugin) Init(ctx context.Context, initParams plugin.InitParams) {
|
|||
}
|
||||
})
|
||||
|
||||
r.reloadMCPServers(ctx)
|
||||
// Delay MCP servers reload to avoid websocket server initialization race condition
|
||||
util.Go(ctx, "reload MCP servers", func() {
|
||||
time.Sleep(time.Millisecond * 1000) // Wait for websocket server to be ready
|
||||
r.reloadMCPServers(util.NewTraceContext())
|
||||
})
|
||||
}
|
||||
|
||||
func (r *AIChatPlugin) IsAutoFocusToChatInputWhenOpenWithQueryHotkey(ctx context.Context) bool {
|
||||
|
|
|
@ -127,6 +127,12 @@ func serveAndWait(ctx context.Context, port int) {
|
|||
}
|
||||
|
||||
func requestUI(ctx context.Context, request WebsocketMsg) error {
|
||||
// Check if melody websocket server is initialized
|
||||
if m == nil {
|
||||
logger.Warn(ctx, fmt.Sprintf("websocket server not ready, skipping UI request: %s", request.Method))
|
||||
return fmt.Errorf("websocket server not initialized")
|
||||
}
|
||||
|
||||
request.Type = WebsocketMsgTypeRequest
|
||||
request.Success = true
|
||||
marshalData, marshalErr := json.Marshal(request)
|
||||
|
@ -141,6 +147,12 @@ func requestUI(ctx context.Context, request WebsocketMsg) error {
|
|||
}
|
||||
|
||||
func responseUI(ctx context.Context, response WebsocketMsg) {
|
||||
// Check if melody websocket server is initialized
|
||||
if m == nil {
|
||||
logger.Warn(ctx, fmt.Sprintf("websocket server not ready, skipping UI response: %s", response.Method))
|
||||
return
|
||||
}
|
||||
|
||||
response.Type = WebsocketMsgTypeResponse
|
||||
marshalData, marshalErr := json.Marshal(response)
|
||||
if marshalErr != nil {
|
||||
|
|
Loading…
Reference in New Issue