Skip to content

Commit 3f3e201

Browse files
authored
fix: fix http cache dir creation order in coderdtest (#17303)
fixes coder/internal#565 Fixes the ordering of creating the HTTP cache temp dir with respect to starting the Coderd HTTP server, so that they are cleaned up in the correct (reverse) order.
1 parent 43b1a03 commit 3f3e201

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
405405
workspacestats.TrackerWithTickFlush(options.WorkspaceUsageTrackerTick, options.WorkspaceUsageTrackerFlush),
406406
)
407407

408+
// create the TempDir for the HTTP file cache BEFORE we start the server and set a t.Cleanup to close it. TempDir()
409+
// registers a Cleanup function that deletes the directory, and Cleanup functions are called in reverse order. If
410+
// we don't do this, then we could try to delete the directory before the HTTP server is done with all files in it,
411+
// which on Windows will fail (can't delete files until all programs have closed handles to them).
412+
cacheDir := t.TempDir()
413+
408414
var mutex sync.RWMutex
409415
var handler http.Handler
410416
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -515,7 +521,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
515521
AppHostname: options.AppHostname,
516522
AppHostnameRegex: appHostnameRegex,
517523
Logger: *options.Logger,
518-
CacheDir: t.TempDir(),
524+
CacheDir: cacheDir,
519525
RuntimeConfig: runtimeManager,
520526
Database: options.Database,
521527
Pubsub: options.Pubsub,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy