-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: fix issue with mcp bind website #8356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,10 +279,12 @@ func (m McpServerService) BindDomain(req request.McpBindDomain) error { | |
| return buserr.New("ErrSSL") | ||
| } | ||
| } | ||
| group, _ := groupRepo.Get(groupRepo.WithByWebsiteDefault()) | ||
| createWebsiteReq := request.WebsiteCreate{ | ||
| PrimaryDomain: req.Domain, | ||
| Alias: strings.ToLower(req.Domain), | ||
| Type: constant.Static, | ||
| PrimaryDomain: req.Domain, | ||
| Alias: strings.ToLower(req.Domain), | ||
| Type: constant.Static, | ||
| WebsiteGroupID: group.ID, | ||
| } | ||
| websiteService := NewIWebsiteService() | ||
| if err := websiteService.CreateWebsite(createWebsiteReq); err != nil { | ||
|
|
@@ -386,13 +388,16 @@ func updateMcpConfig(websiteID uint) { | |
| } else { | ||
| baseUrl = fmt.Sprintf("https://%s", websiteDomain.Domain) | ||
| } | ||
| for _, server := range servers { | ||
| if server.BaseURL != baseUrl { | ||
| server.BaseURL = baseUrl | ||
| server.HostIP = "127.0.0.1" | ||
| go updateMcpServer(&server) | ||
|
|
||
| go func() { | ||
| for _, server := range servers { | ||
| if server.BaseURL != baseUrl { | ||
| server.BaseURL = baseUrl | ||
| server.HostIP = "127.0.0.1" | ||
| _ = updateMcpServer(&server) | ||
| } | ||
| } | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| func addProxy(server *model.McpServer) { | ||
|
|
@@ -502,13 +507,13 @@ func updateMcpServer(mcpServer *model.McpServer) error { | |
| if err := gotenv.Write(env, path.Join(mcpServer.Dir, ".env")); err != nil { | ||
| return err | ||
| } | ||
| _ = mcpServerRepo.Save(mcpServer) | ||
| composePath := path.Join(constant.McpDir, mcpServer.Name, "docker-compose.yml") | ||
| _, _ = compose.Down(composePath) | ||
| if _, err := compose.Up(composePath); err != nil { | ||
| mcpServer.Status = constant.RuntimeError | ||
| mcpServer.Message = err.Error() | ||
| } | ||
|
|
||
| return mcpServerRepo.Save(mcpServer) | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has several issues that can be addressed:
To address these issues:
Here's an optimized version of the affected part of the code: var wg sync.WaitGroup
for _, server := range servers {
wg.Add(1)
go func(s *model.McpServer) {
defer wg.Done()
if server.BaseURL != baseUrl {
server.BaseURL = baseUrl
server.HostIP = "127.0.0.1"
if err := updateMcpServer(s); err != nil {
log.Printf("Failed to update MCP Server %s: %v", s.Name, err)
} else {
mcpServerRepo.Save(s) // Ensure this call is successful before updating docker-compose.
}
}
composePath := path.Join(constant.McpDir, s.Name, "docker-compose.yml")
_, _ = compose.Down(composePath)
if _, err := compose.Up(composePath); err != nil {
s.Status = constant.RuntimeError
s.Message = err.Error()
mcpServerRepo.Save(s)
}
}(server)
}
wg.Wait() // Wait for all goroutines to complete.This version ensures that each server update operation runs concurrently using channels. It also includes logging for failed operations to help debug potential issues later on. Make sure to initialize the waitgroup correctly at the start of the function and ensure |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one change made in this patch. The function
WithByWebsiteDefaulthas been added to theIGroupRepointerface and also implemented in theGroupRepostruct. This likely adds functionality for filtering groups that are both default and have a specific group type ("website") when performing database queries.Optimization suggestions: No apparent performance improvements can be directly suggested from this single-line addition, but having more methods on an interface could potentially make the implementation slightly more modular or easier to maintain depending on future use cases.