Merge branch 'main' into 15397-remove-obsolete-apis
[arvados.git] / services / keep-web / handler.go
index 4fae0aee5f1e1fec81186f5206d3cd06ea41a4ea..b9250efec76b8b45f599c30dc8961cbc3e279474 100644 (file)
@@ -435,6 +435,14 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                break
        }
 
+       // releaseSession() is equivalent to session.Release() except
+       // that it's a no-op if (1) session is nil, or (2) it has
+       // already been called.
+       //
+       // This way, we can do a defer call here to ensure it gets
+       // called in all code paths, and also call it inline (see
+       // below) in the cases where we want to release the lock
+       // before returning.
        releaseSession := func() {}
        if session != nil {
                var releaseSessionOnce sync.Once
@@ -603,7 +611,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                // When writing, we need to block session renewal
                // until we're finished, in order to guarantee the
                // effect of the write is visible in future responses.
-               // But if we're not writing, we can release the lcok
+               // But if we're not writing, we can release the lock
                // early.  This enables us to keep renewing sessions
                // and processing more requests even if a slow client
                // takes a long time to download a large file.