server: Cancel context on IO errors

This commit is contained in:
Adnan Maolood 2021-02-23 16:06:57 -05:00
parent d07e9d99d1
commit 833edaf63d

View File

@ -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()