Skip to content

Commit

Permalink
Merge pull request #1284 from skrashevich/fix-apiinit-datarace
Browse files Browse the repository at this point in the history
refactor(api): move port extraction logic to Init function for prevent data race
  • Loading branch information
AlexxIT authored Feb 21, 2025
2 parents 4897994 + 23e8f7e commit 33f4bb4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func Init() {
}

if cfg.Mod.Listen != "" {
_, port, _ := net.SplitHostPort(cfg.Mod.Listen)
Port, _ = strconv.Atoi(port)
go listen("tcp", cfg.Mod.Listen)
}

Expand All @@ -92,10 +94,6 @@ func listen(network, address string) {

log.Info().Str("addr", address).Msg("[api] listen")

if network == "tcp" {
Port = ln.Addr().(*net.TCPAddr).Port
}

server := http.Server{
Handler: Handler,
ReadHeaderTimeout: 5 * time.Second, // Example: Set to 5 seconds
Expand Down

0 comments on commit 33f4bb4

Please sign in to comment.