From ce21b32d38f7506356c8f09ea233dd898daf1feb Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 1 Jun 2017 14:44:00 +0200 Subject: [PATCH] mediaapi/writers/download: Wrap broadcast call in closure to re-evaluate args --- .../matrix-org/dendrite/mediaapi/writers/download.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 eac5d764..65f4572a 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -226,9 +226,11 @@ func (r *downloadRequest) getRemoteFile(cfg *config.MediaAPI, db *storage.Databa r.MediaMetadata = mediaMetadata } else { // Note: This is an active request that MUST broadcastMediaMetadata to wake up waiting goroutines! - // Note: errorResponse is the named return variable // Note: broadcastMediaMetadata uses mutexes and conditions from activeRemoteRequests - defer r.broadcastMediaMetadata(activeRemoteRequests, errorResponse) + defer func() { + // Note: errorResponse is the named return variable so we wrap this in a closure to re-evaluate the arguments at defer-time + r.broadcastMediaMetadata(activeRemoteRequests, errorResponse) + }() // check if we have a record of the media in our database mediaMetadata, err := db.GetMediaMetadata(r.MediaMetadata.MediaID, r.MediaMetadata.Origin)