File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,17 @@ import (
60
60
"github.com/coder/coder/tailnet"
61
61
)
62
62
63
+ // We must only ever instantiate one httpSwagger.Handler because of a data race
64
+ // inside the handler. This issue is triggered by tests that create multiple
65
+ // coderd instances.
66
+ //
67
+ // See https://github.com/swaggo/http-swagger/issues/78
68
+ var globalHTTPSwaggerHandler http.HandlerFunc
69
+
70
+ func init () {
71
+ globalHTTPSwaggerHandler = httpSwagger .Handler (httpSwagger .URL ("/swagger/doc.json" ))
72
+ }
73
+
63
74
// Options are requires parameters for Coder to start.
64
75
type Options struct {
65
76
AccessURL * url.URL
@@ -599,7 +610,9 @@ func New(options *Options) *API {
599
610
// Swagger UI requires the URL trailing slash. Otherwise, the browser tries to load /assets
600
611
// from http://localhost:8080/assets instead of http://localhost:8080/swagger/assets.
601
612
r .Get ("/swagger" , http .RedirectHandler ("/swagger/" , http .StatusTemporaryRedirect ).ServeHTTP )
602
- r .Get ("/swagger/*" , httpSwagger .Handler (httpSwagger .URL ("/swagger/doc.json" )))
613
+ // See globalHTTPSwaggerHandler comment as to why we use a package
614
+ // global variable here.
615
+ r .Get ("/swagger/*" , globalHTTPSwaggerHandler )
603
616
}
604
617
605
618
r .NotFound (compressHandler (http .HandlerFunc (api .siteHandler .ServeHTTP )).ServeHTTP )
You can’t perform that action at this time.
0 commit comments