feat: add server listening functionality with retry mechanism and platform-specific shutdown signal handling for improved robustness

This commit is contained in:
wizardchen
2026-04-11 19:08:17 +08:00
committed by lyingbug
parent 4af7885d13
commit ae95cb1a7a
5 changed files with 52 additions and 3 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ jobs:
- os: ubuntu-24.04-arm
goos: linux
goarch: arm64
- os: macos-13
- os: macos-14
goos: darwin
goarch: amd64
- os: macos-14
@@ -143,7 +143,7 @@ jobs:
platform: darwin/universal
arch_label: macOS_universal
artifact_name: desktop-macos-universal
- os: macos-13
- os: macos-14
platform: darwin/amd64
arch_label: macOS_amd64
artifact_name: desktop-macos-amd64
+1 -1
View File
@@ -41,7 +41,7 @@ web/
**/__pycache__
/scripts/scale_dev_jobs.sh
server
/server
frontend/.vite
frontend/chrome-extension/
WeKnora-Chrome-Extension
+29
View File
@@ -0,0 +1,29 @@
package main
import (
"context"
"net"
"time"
"github.com/Tencent/WeKnora/internal/logger"
)
func listenWithRetry(addr string, maxRetries int, baseDelay time.Duration) (net.Listener, error) {
var lastErr error
for i := 0; i < maxRetries; i++ {
listener, err := net.Listen("tcp", addr)
if err == nil {
return listener, nil
}
lastErr = err
if i < maxRetries-1 {
delay := baseDelay * time.Duration(1<<uint(i))
if delay > 3*time.Second {
delay = 3 * time.Second
}
logger.Warnf(context.Background(), "Port %s in use, retrying in %v... (%d/%d)", addr, delay, i+1, maxRetries)
time.Sleep(delay)
}
}
return nil, lastErr
}
+10
View File
@@ -0,0 +1,10 @@
//go:build !windows
package main
import (
"os"
"syscall"
)
var shutdownSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP}
+10
View File
@@ -0,0 +1,10 @@
//go:build windows
package main
import (
"os"
"syscall"
)
var shutdownSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM}