Skip to content

Commit ee23c92

Browse files
committed
wrap more panics
1 parent 2687864 commit ee23c92

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

receiver/libhoneyreceiver/receiver.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,34 @@ func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Reque
234234
// Don't try to drain body if we got an error from compressed reader
235235
// The reader may be in a corrupted state and cause another panic
236236
if req.Body != nil {
237-
_ = req.Body.Close()
237+
func() {
238+
defer func() {
239+
if panicVal := recover(); panicVal != nil {
240+
r.settings.Logger.Debug("Panic during body close after read error (expected with corrupted data)",
241+
zap.Any("panic", panicVal))
242+
}
243+
}()
244+
_ = req.Body.Close()
245+
}()
238246
}
239247
return
240248
}
241-
if err = req.Body.Close(); err != nil {
242-
r.settings.Logger.Error("Failed to close request body", zap.Error(err))
243-
writeLibhoneyError(resp, enc, "failed to close request body")
249+
func() {
250+
defer func() {
251+
if panicVal := recover(); panicVal != nil {
252+
r.settings.Logger.Error("Panic during request body close",
253+
zap.Any("panic", panicVal))
254+
writeLibhoneyError(resp, enc, "failed to close request body")
255+
err = errors.New("panic during body close")
256+
}
257+
}()
258+
err = req.Body.Close()
259+
}()
260+
if err != nil {
261+
if !strings.Contains(err.Error(), "panic during body close") {
262+
r.settings.Logger.Error("Failed to close request body", zap.Error(err))
263+
writeLibhoneyError(resp, enc, "failed to close request body")
264+
}
244265
return
245266
}
246267
libhoneyevents := make([]libhoneyevent.LibhoneyEvent, 0)

0 commit comments

Comments
 (0)