Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set timeout for idle connections #55064

Closed
himaniarora2020 opened this issue Sep 14, 2022 · 1 comment
Closed

Unable to set timeout for idle connections #55064

himaniarora2020 opened this issue Sep 14, 2022 · 1 comment

Comments

@himaniarora2020
Copy link

I am new to go language and want to set an HTTP timeout for requests and connections that have been idle for 10 seconds. I have added a code like so:

func handleServerConn(customer models.User, chans <-chan ssh.NewChannel) {

    for newChan := range chans {

        log.Debugf("New Channel: %v", newChan.ChannelType())

        if newChan.ChannelType() != "session" {
            log.Errorw("channel type rejected", log.Fields{"user": customer.LogFields(), "type": newChan.ChannelType()})
            newChan.Reject(ssh.UnknownChannelType, "unknown channel type")
            continue
        }

        ch, reqs, err := newChan.Accept()
        if err != nil {
            log.Infow("error accepting channel", log.Fields{"user": customer.LogFields(), "error": err})
            continue
        }

        /*
         * Send keepalive pings every now and then so that ELB wont disconnect the client
         */
        go func() {
            var errPing error
            var pingret bool
            for ch != nil && errPing != io.EOF {
                time.Sleep(60 * time.Second)
                pingret, errPing = ch.SendRequest("ping", false, nil)
                log.Debugw("sending ping", log.Fields{"error": err, "return": pingret})
            }
        }()

        serv := &http.Server{
            IdleTimeout: 10 * time.Second,
        }
        serv.ListenAndServe()
        log.Infow("Timeout reached for 10 seconds", log.Fields{"Read timeout response": resp, "Write timeout": resp})
--rest of the code
}

But the server goes on without terminating the connection. Is the placement for the timeout function correct? What else can be done here?

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2022
@golang golang locked and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants