From cae309fa2644ac3753f1e5bb3c0eb6e8a5307a72 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 1 Jun 2017 14:54:59 +0200 Subject: [PATCH] mediaapi/writers/download: Handle panic to ensure waking of goroutines If the active request were to panic, we need to ensure all the waiting goroutines get woken up. --- .../matrix-org/dendrite/mediaapi/writers/download.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go index 65f4572a..c320e512 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -229,6 +229,11 @@ func (r *downloadRequest) getRemoteFile(cfg *config.MediaAPI, db *storage.Databa // Note: broadcastMediaMetadata uses mutexes and conditions from activeRemoteRequests defer func() { // Note: errorResponse is the named return variable so we wrap this in a closure to re-evaluate the arguments at defer-time + if err := recover(); err != nil { + resErr := jsonerror.InternalServerError() + r.broadcastMediaMetadata(activeRemoteRequests, &resErr) + panic(err) + } r.broadcastMediaMetadata(activeRemoteRequests, errorResponse) }()