2

I have the following go code:

package main

import (
   "net/http"
    "github.com/labstack/echo"
)
func main() {
e := echo.New()
e.POST("/getRequestData", respond)
e.Logger.Fatal(e.Start(":80"))
}

func respond(c echo.Context) error {

        resp := map[string]string{ "value": "key"}
        return c.JSON(http.StatusOK, resp)
}

I want that connections toward this server will be open up to 10 min of inactivity. What I see that every few minutes I get Ack from the server, which causes it to remain open indefinitely. How do I turn off keep-Alive in go?

Thanks.

itayb
  • 139
  • 3
  • 10
  • 2
    *".... I get Ack from the server, which causes it to remain open indefinitely ..."* - An ACK at the TCP level is unrelated to idle timeout at the application level. TCP keep alive is only about keeping states open in intermediate firewalls and realizing connectivity loss even if no data are transferred. – Steffen Ullrich Jun 01 '21 at 08:52

1 Answers1

2

This was mentioned in 2011 with issue 2011 (server side), and resolved in commit ac213ab.
That allows to set HTTP.Transport configuration like DisableKeepAlives to true, and MaxIdleConnsPerHost to -1 and have those settings respected.

But implementing an Hijacker as in here is also an option if you need more control over the TCP connection.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250