From 4d4753b0a2c4d75790c18c44d3e5b106b5957dac Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 26 Oct 2021 09:27:56 +0200 Subject: [PATCH] Add comment about copying context --- internal/http/services/owncloud/ocs/cache.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/http/services/owncloud/ocs/cache.go b/internal/http/services/owncloud/ocs/cache.go index ea587ae5fab..edb64edfcdc 100644 --- a/internal/http/services/owncloud/ocs/cache.go +++ b/internal/http/services/owncloud/ocs/cache.go @@ -34,6 +34,10 @@ func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) { tkn := ctxpkg.ContextMustGetToken(r.Context()) log := appctx.GetLogger(r.Context()) + // We make a copy of the context because the original one comes with + // its context channel, so once the initial request is finished, this ctx gets cancelled as well. + // And in most of the cases, it takes a longer amount of time to complete than the original request. + // TODO: Check if we can come up with a better solution, eg, https://stackoverflow.com/a/54132324 ctx := context.Background() ctx = appctx.WithLogger(ctx, log) ctx = ctxpkg.ContextSetUser(ctx, u)