Skip to content

net/http: ResponseWriter leaves connection open after WriteTimeout #8534

Closed
@jbardin

Description

@jbardin
go1.3.1

run the following http server:


```
package main

import (
    "fmt"
    "net/http"
    "time"
)

func handler(w http.ResponseWriter, r *http.Request) {
    time.Sleep(2 * time.Second)
    msg := []byte("Hello world!\n")
    n, err := w.Write(msg)
    fmt.Printf("Wrote %d out of %d bytes\n", n, len(msg))
    fmt.Println("Error was:", err)
}
func main() {
    http.HandleFunc("/", handler)
    server := http.Server{
        Addr:         ":8123",
        ReadTimeout:  time.Second,
        WriteTimeout: time.Second,
    }
    server.ListenAndServe()
}
```

What happens:

The Write always succeeds in this handler, and the connection is left open hanging the
client. 


What should happen:

- Connection closed due to timeout
- Preferably return an error when writes fail (though this may not be feasible due to
internal buffering)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions