It seems even if the connection is lost, the handler function is still running. For example, if I visit http://0.0.0.0:8000/home and close the browser suddenly, the screen will continue to print all the numbers.
package main
import (
"fmt"
"net/http"
"time"
)
func main() {
http.HandleFunc("/home", func(w http.ResponseWriter, r *http.Request) {
i := 0
for {
fmt.Println("i", i)
i++
time.Sleep(time.Microsecond * 15)
}
})
http.ListenAndServe(":8000", nil)
}
related: How golang gin stop handler function immediately if connection is lost