Skip to content

Commit f06a17d

Browse files
committed
feature: Port free up when starting server
1 parent f4b86e4 commit f06a17d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/utils/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package utils
22

33
import (
4+
"strings"
5+
"time"
6+
47
"github.com/bytedance/sonic"
58
"github.com/gofiber/fiber/v2"
69
"github.com/gofiber/fiber/v2/middleware/compress"
@@ -41,8 +44,12 @@ func CreateServer() {
4144
// Start server
4245
err := app.ListenTLS(":2806", constants.CERT_PATH+"/liman.crt", constants.CERT_PATH+"/liman.key")
4346
if err != nil {
44-
linux.Execute("fuser -k 2806/tcp")
4547
logger.Sugar().Errorw("app initialization error", "details", err)
46-
helpers.RestartSelf()
48+
if strings.Contains(err.Error(), "listen tcp4 :2806: bind: address already in use") {
49+
logger.Sugar().Infow("restarting app to freeup port")
50+
linux.Execute("fuser -k 2806/tcp")
51+
time.Sleep(time.Second)
52+
helpers.RestartSelf()
53+
}
4754
}
4855
}

0 commit comments

Comments
 (0)