1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-27 09:55:22 +00:00

protect against writing to closed body

This commit is contained in:
Darien Raymond 2018-03-21 12:53:57 +01:00
parent bf5e93efd7
commit e647292b9a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -31,9 +31,14 @@ func (l *Listener) Close() error {
type flushWriter struct {
w io.Writer
d *signal.Done
}
func (fw flushWriter) Write(p []byte) (n int, err error) {
if fw.d.Done() {
return 0, io.ErrClosedPipe
}
n, err = fw.w.Write(p)
if f, ok := fw.w.(http.Flusher); ok {
f.Flush()
@ -61,8 +66,8 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request)
done := signal.NewDone()
l.handler(&Connection{
Reader: request.Body,
Writer: flushWriter{writer},
Closer: common.NewChainedClosable(request.Body, done),
Writer: flushWriter{w: writer, d: done},
Closer: common.NewChainedClosable(done, request.Body),
Local: l.Addr(),
Remote: l.Addr(),
})