Http timeouts are not being fully enforced when load testing

I been load testing my application and I notice that at times the connections do not timeout and I have to manually cancel the process . How can I make sure that timeouts work correctly every time ? This is my code

    ```
    package main

   import (
"github.com/gorilla/mux"
"net/http"
"./Controllers"
"runtime"
"time"
"log")

  func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	r := mux.NewRouter()


	r.HandleFunc("/registration",Controllers.Registration)
	r.HandleFunc("/login",Controllers.Login)



	r.HandleFunc("/test",Controllers.Mytest)

        // This only displays html page
	r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("Views/"))))

	http.Handle("/",r)

	srv := &http.Server{
		ReadTimeout: 5 * time.Second,
		WriteTimeout: 5 * time.Second,
		Handler: nil,
		Addr: ":8000",
	}

	log.Println(srv.ListenAndServe())
} ```

This image below shows that the last 3 requests takes about 120 seconds when I have the Timeouts set to 5 seconds. Any suggestions would be great as I am new to Golang

Not really an answer but I found this interesting article about Go’s http timeouts that shares some insights about the topic.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.