Browse Source

fix: unable to close local proxy

master
pcong 5 months ago
parent
commit
e48ff4b241
  1. 8
      godo/proxy/local.go

8
godo/proxy/local.go

@ -135,8 +135,10 @@ func UpdateLocalProxyHandler(w http.ResponseWriter, r *http.Request) {
// 停止旧的代理服务 // 停止旧的代理服务
stopProxy(lp.ID) stopProxy(lp.ID)
// 启动新的代理服务 if !lp.Status {
go startProxy(lp) // 启动新的代理服务
go startProxy(lp)
}
libs.SuccessMsg(w, lp, "") libs.SuccessMsg(w, lp, "")
} }
@ -237,11 +239,13 @@ func stopProxy(id uint) {
switch proxyServer.Type { switch proxyServer.Type {
case "http": case "http":
fmt.Println("closing http proxy...")
httpServer, ok := proxyServer.Server.(*http.Server) httpServer, ok := proxyServer.Server.(*http.Server)
if ok { if ok {
// 创建一个上下文,用于传递给 server.Shutdown(ctx) // 创建一个上下文,用于传递给 server.Shutdown(ctx)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
defer httpServer.Close()
if err := httpServer.Shutdown(ctx); err != nil { if err := httpServer.Shutdown(ctx); err != nil {
fmt.Printf("Failed to shutdown HTTP server on port %s: %v\n", httpServer.Addr, err) fmt.Printf("Failed to shutdown HTTP server on port %s: %v\n", httpServer.Addr, err)
} else { } else {

Loading…
Cancel
Save