mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
[ws-proxy] Don't leak workspace info Go routines
This commit is contained in:
parent
1ac8fbeef3
commit
396b51ed1f
@ -275,8 +275,15 @@ func mapWorkspaceStatusToInfo(status *wsapi.WorkspaceStatus) *WorkspaceInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkspaceInfo return the WorkspaceInfo avaiable for the given workspaceID
|
// WorkspaceInfo return the WorkspaceInfo avaiable for the given workspaceID.
|
||||||
|
// Callers should make sure their context gets canceled properly. For good measure
|
||||||
|
// this function will timeout by itself as well.
|
||||||
func (p *RemoteWorkspaceInfoProvider) WorkspaceInfo(ctx context.Context, workspaceID string) *WorkspaceInfo {
|
func (p *RemoteWorkspaceInfoProvider) WorkspaceInfo(ctx context.Context, workspaceID string) *WorkspaceInfo {
|
||||||
|
// In case the parent context does not cancel for some reason, we want to make sure
|
||||||
|
// we clean up after ourselves to not leak Go routines.
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
info, present := p.cache.WaitFor(ctx, workspaceID)
|
info, present := p.cache.WaitFor(ctx, workspaceID)
|
||||||
if !present {
|
if !present {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -482,10 +482,7 @@ func workspaceMustExistHandler(config *Config, infoProvider WorkspaceInfoProvide
|
|||||||
return func(h http.Handler) http.Handler {
|
return func(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||||
coords := getWorkspaceCoords(req)
|
coords := getWorkspaceCoords(req)
|
||||||
// it might take some time until the event comes in. Let's wait for it at most 3 secs.
|
info := infoProvider.WorkspaceInfo(req.Context(), coords.ID)
|
||||||
ctx, cancel := context.WithTimeout(req.Context(), 3*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
info := infoProvider.WorkspaceInfo(ctx, coords.ID)
|
|
||||||
if info == nil {
|
if info == nil {
|
||||||
log.WithFields(log.OWI("", coords.ID, "")).Info("no workspace info found - redirecting to start")
|
log.WithFields(log.OWI("", coords.ID, "")).Info("no workspace info found - redirecting to start")
|
||||||
redirectURL := fmt.Sprintf("%s://%s/start/#%s", config.GitpodInstallation.Scheme, config.GitpodInstallation.HostName, coords.ID)
|
redirectURL := fmt.Sprintf("%s://%s/start/#%s", config.GitpodInstallation.Scheme, config.GitpodInstallation.HostName, coords.ID)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user