From 8a82af004007fae5912aab259818fa798301243c Mon Sep 17 00:00:00 2001 From: Dingjun Date: Mon, 7 Aug 2017 10:57:34 +0800 Subject: [PATCH] handle panic when forward the data between the two connections, if one end close the connection, this will cause panic when write to closed connection --- handler.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/handler.go b/handler.go index df913cb..821ff40 100644 --- a/handler.go +++ b/handler.go @@ -167,6 +167,12 @@ func (h *handler) handleCONNECT(w http.ResponseWriter, r *http.Request) { // HTTP/2.0 + defer func() { + if err := recover(); err != nil { + log.Printf("recover %+v", err) + } + }() + defer conn.Close() w.WriteHeader(http.StatusOK) @@ -212,6 +218,12 @@ func (h *handler) isLocalRequest(r *http.Request) bool { } func pipeAndClose(r1, r2 io.ReadWriteCloser) { + defer func() { + if err := recover(); err != nil { + log.Printf("recover %+v", err) + } + }() + defer r1.Close() defer r2.Close()