Skip to content

Commit 396b51e

Browse files
author
Christian Weichel
committed
[ws-proxy] Don't leak workspace info Go routines
1 parent 1ac8fbe commit 396b51e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

components/ws-proxy/pkg/proxy/infoprovider.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,15 @@ func mapWorkspaceStatusToInfo(status *wsapi.WorkspaceStatus) *WorkspaceInfo {
275275
}
276276
}
277277

278-
// WorkspaceInfo return the WorkspaceInfo avaiable for the given workspaceID
278+
// WorkspaceInfo return the WorkspaceInfo avaiable for the given workspaceID.
279+
// Callers should make sure their context gets canceled properly. For good measure
280+
// this function will timeout by itself as well.
279281
func (p *RemoteWorkspaceInfoProvider) WorkspaceInfo(ctx context.Context, workspaceID string) *WorkspaceInfo {
282+
// In case the parent context does not cancel for some reason, we want to make sure
283+
// we clean up after ourselves to not leak Go routines.
284+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
285+
defer cancel()
286+
280287
info, present := p.cache.WaitFor(ctx, workspaceID)
281288
if !present {
282289
return nil

components/ws-proxy/pkg/proxy/routes.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,7 @@ func workspaceMustExistHandler(config *Config, infoProvider WorkspaceInfoProvide
482482
return func(h http.Handler) http.Handler {
483483
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
484484
coords := getWorkspaceCoords(req)
485-
// it might take some time until the event comes in. Let's wait for it at most 3 secs.
486-
ctx, cancel := context.WithTimeout(req.Context(), 3*time.Second)
487-
defer cancel()
488-
info := infoProvider.WorkspaceInfo(ctx, coords.ID)
485+
info := infoProvider.WorkspaceInfo(req.Context(), coords.ID)
489486
if info == nil {
490487
log.WithFields(log.OWI("", coords.ID, "")).Info("no workspace info found - redirecting to start")
491488
redirectURL := fmt.Sprintf("%s://%s/start/#%s", config.GitpodInstallation.Scheme, config.GitpodInstallation.HostName, coords.ID)

0 commit comments

Comments
 (0)