server: Cancel context on IO errors
This commit is contained in:
parent
d07e9d99d1
commit
833edaf63d
19
server.go
19
server.go
@ -344,9 +344,24 @@ func (srv *Server) ServeConn(ctx context.Context, conn net.Conn) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) serveConn(ctx context.Context, conn net.Conn) error {
|
func (srv *Server) serveConn(ctx context.Context, conn net.Conn) error {
|
||||||
w := newResponseWriter(conn)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
done := ctx.Done()
|
||||||
|
cw := &contextWriter{
|
||||||
|
ctx: ctx,
|
||||||
|
done: done,
|
||||||
|
cancel: cancel,
|
||||||
|
wc: conn,
|
||||||
|
}
|
||||||
|
r := &contextReader{
|
||||||
|
ctx: ctx,
|
||||||
|
done: done,
|
||||||
|
cancel: cancel,
|
||||||
|
rc: conn,
|
||||||
|
}
|
||||||
|
|
||||||
req, err := ReadRequest(conn)
|
w := newResponseWriter(cw)
|
||||||
|
|
||||||
|
req, err := ReadRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(StatusBadRequest, "Bad request")
|
w.WriteHeader(StatusBadRequest, "Bad request")
|
||||||
return w.Flush()
|
return w.Flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user