Skip to content

Commit

Permalink
Make stopping last longer
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed May 15, 2024
1 parent 5ff4535 commit d884535
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# See License.AGPL.txt in the project root for license information.

set -Eeuo pipefail
source /workspace/gitpod/scripts/ws-deploy.sh deployment dashboard
source /workspace/gitpod/scripts/ws-deploy.sh deployment dashboard false
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-wor
import { useCurrentOrg } from "../organizations/orgs-query";
import { stream, workspaceClient } from "../../service/public-api";
import {
WatchWorkspaceStatusRequest,
WatchWorkspaceStatusResponse,
Workspace,
WorkspacePhase_Phase,
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";

export const useListenToWorkspacesWSMessages = () => {
Expand Down Expand Up @@ -54,8 +54,17 @@ export const useListenToWorkspacesWSMessages = () => {
export type WatchWorkspaceStatusCallback = (response: WatchWorkspaceStatusResponse) => Promise<void> | void;

export function watchWorkspaceStatus(workspaceId: string | undefined, cb: WatchWorkspaceStatusCallback): Disposable {
return stream<WatchWorkspaceStatusRequest>(
console.log(new Date(), "=================watchWorkspaceStatus", workspaceId);
return stream<WatchWorkspaceStatusResponse>(
(options) => workspaceClient.watchWorkspaceStatus({ workspaceId }, options),
cb,
async (resp) => {
console.log(
new Date(),
"==============receive",
resp.workspaceId,
WorkspacePhase_Phase[resp.status?.phase?.name ?? WorkspacePhase_Phase.UNSPECIFIED],
);
return cb(resp);
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function watchWorkspaceStatusInOrder(
callbacks.sort((a, b) => b.priority - a.priority);

if (!cachedDisposables.has(wsID)) {
console.log(new Date(), "=================watchWorkspaceStatusInOrder", workspaceId);
const disposable = watchWorkspaceStatus(wsID, async (response) => {
const list = cachedCallbackInfoMap.get(wsID);
if (!list) {
Expand Down
9 changes: 8 additions & 1 deletion components/dashboard/src/service/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export function stream<Response>(
const abort = new AbortController();
(async () => {
while (!abort.signal.aborted) {
console.log(new Date(), "=================stream.started");
try {
for await (const response of factory({
signal: abort.signal,
Expand All @@ -289,6 +290,7 @@ export function stream<Response>(
}
} catch (e) {
if (abort.signal.aborted) {
console.log(new Date(), "=================stream.aborted");
// client aborted, don't reconnect, early exit
return;
}
Expand All @@ -299,9 +301,11 @@ export function stream<Response>(
// (clean up when fixed, on server abort we should rather backoff with jitter)
e.code === ErrorCodes.CANCELLED)
) {
console.log(new Date(), "=================stream.hitErr", e.code);
// timeout is expected, reconnect with base backoff
backoff = BASE_BACKOFF;
} else {
console.log(new Date(), "=================stream.err", e);
backoff = Math.min(2 * backoff, MAX_BACKOFF);
console.error(e);
}
Expand All @@ -312,5 +316,8 @@ export function stream<Response>(
}
})();

return Disposable.create(() => abort.abort());
return Disposable.create(() => {
console.log(new Date(), "=================stream.disposed");
abort.abort();
});
}
10 changes: 5 additions & 5 deletions components/supervisor/pkg/supervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ func (c WorkspaceConfig) getCommit() (commit *gitpod.Commit, err error) {
}

func (c WorkspaceConfig) GetTerminationGracePeriod() time.Duration {
defaultGracePeriod := 15 * time.Second
if c.TerminationGracePeriodSeconds == nil || *c.TerminationGracePeriodSeconds <= 0 {
return defaultGracePeriod
}
return time.Duration(*c.TerminationGracePeriodSeconds) * time.Second
defaultGracePeriod := 15 * time.Minute
// if c.TerminationGracePeriodSeconds == nil || *c.TerminationGracePeriodSeconds <= 0 {
return defaultGracePeriod
// }
// return time.Duration(*c.TerminationGracePeriodSeconds) * time.Second
}

// GetConfig loads the supervisor configuration.
Expand Down
1 change: 1 addition & 0 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ func Run(options ...RunOption) {
stopGitStatus()
gitStatusWg.Wait()

time.Sleep(20 * time.Minute)
terminalShutdownCtx, cancelTermination := context.WithTimeout(context.Background(), cfg.GetTerminationGracePeriod())
defer cancelTermination()
cancel()
Expand Down
4 changes: 2 additions & 2 deletions components/workspacekit/cmd/rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ const (
//
// This time must give ring1 enough time to shut down (see time budgets in supervisor.go),
// and to talk to ws-daemon within the terminationGracePeriod of the workspace pod.
ring1ShutdownTimeout = 20 * time.Second
ring1ShutdownTimeout = 20 * time.Minute

// ring2StartupTimeout is the maximum time we wait between starting ring2 and its
// attempt to connect to the parent socket.
ring2StartupTimeout = 5 * time.Second
ring2StartupTimeout = 5 * time.Minute
)

var ring0Cmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion components/ws-manager-mk2/service/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (

const (
// stopWorkspaceNormallyGracePeriod is the grace period we use when stopping a pod with StopWorkspaceNormally policy
stopWorkspaceNormallyGracePeriod = 30 * time.Second
stopWorkspaceNormallyGracePeriod = 30 * time.Minute
// stopWorkspaceImmediatelyGracePeriod is the grace period we use when stopping a pod as soon as possbile
stopWorkspaceImmediatelyGracePeriod = 1 * time.Second
)
Expand Down

0 comments on commit d884535

Please sign in to comment.