为什么在几个请求后,此go http服务器停止响应?

I'm building a Go http server which listens to port 4242. Every request triggers a function of my program. Everything works fine, but after 30/40 requests, It just stops answering.

I Already run the whole program without server (interacting with it via stdin/stdout) and there is no problem or bug. Problem comes only when I trigger it from http requests.

Also, when I add some workload in those functions, I run into the bug faster. I was suspecting a memory problem, but then again, if there is no server, there is no bug.

Server doens't crash, and there is no error message. My function code actually stops being executed at a random line (tried debugging the code and saw that the routine actually stops going through my code and stops at a random place every time)

package server

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "os"
    "strconv"
    "time"

    "github.com/gogogomoku/gomoku/internal/brain"
    "github.com/gorilla/mux"
)

type SimpleResponse struct {
    ResCode int    `json:"code" xml:"code"`
    Message string `json:"message" xml:"message"`
}

func home(w http.ResponseWriter, r *http.Request) {
    // ..
}

func startGame(w http.ResponseWriter, r *http.Request) {
    // ..
}

func restartGame(w http.ResponseWriter, r *http.Request) {
    fmt.Println("Request")
    fmt.Println(r)
    InitializeValues()
    StartRound()
    json.NewEncoder(w).Encode(GameRound)
    fmt.Println("Response")
    fmt.Println(w)
}

func MakeMove(w http.ResponseWriter, r *http.Request) {
    // ...
}

func StartServer() {
    router := mux.NewRouter().StrictSlash(true)
    router.Use(commonMiddleware)
    router.HandleFunc("/", home)
    router.HandleFunc("/start", startGame)
    router.HandleFunc("/restart", restartGame)
    router.HandleFunc("/move/{pos}/id/{id}", MakeMove)
    logger := log.New(os.Stdout, "http: ", log.LstdFlags)
    logger.Println("Server is starting...")
    srv := &http.Server{
        Handler:      router,
        Addr:         "localhost:4242",
        WriteTimeout: 5 * time.Second,
        ReadTimeout:  10 * time.Second,
        IdleTimeout:  15 * time.Second,
        ErrorLog:     logger,
    }
    if err := srv.ListenAndServe(); err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

func commonMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Access-Control-Allow-Origin", "*")
        w.Header().Add("Content-Type", "application/json")
        next.ServeHTTP(w, r)
    })
}

For example, if I do http requests on http://localhost:4242/restart they work fine and I get the json. After 30/35 requests, server seems to freeze, and I get no response, no crash, no message, anything.

Any ideas?

Thanks!

The call to start server was done as a go routine call:

go StartServer()

Removing that seems to fix the problem, but why would that be a problem anyway? (Asuming the routine doesn't hit its last instruction, of course)