Skip to content

conn updates 3 #1711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
15c01d2
remove detectshell and pwsh special case. wrap with sh -c to get fish…
sawka Jan 3, 2025
83ebae8
use wconfig.GetWatcher().GetFullConfig() instead of re-reading the co…
sawka Jan 7, 2025
fe3ead3
Merge remote-tracking branch 'origin/main' into sawka/conn-updates-3
sawka Jan 7, 2025
45f5a7e
switch 'askbeforewshinstall' to a bool ptr. resolve with a new helpe…
sawka Jan 7, 2025
6b44c34
checkpoint on conncontroller refactor
sawka Jan 8, 2025
119e158
change ensureconnection to take a logblockid, pass through into conn …
sawka Jan 8, 2025
c0dab83
blocklogger. hook up to connect command, control with term meta
sawka Jan 8, 2025
860607c
info/debug logs for blocklogger. start logging much more connection …
sawka Jan 8, 2025
398da0d
Merge remote-tracking branch 'origin/main' into sawka/conn-updates-3
sawka Jan 9, 2025
599de92
force serialization of blocklogger events
sawka Jan 10, 2025
48aa730
more logging, use new wsh install flow
sawka Jan 10, 2025
f20b329
refocus after closing connection modal
sawka Jan 10, 2025
26aad51
debugging info through remote sshclient. nowshreason. connect now a…
sawka Jan 10, 2025
b547e83
add stopping blockcontroller log info
sawka Jan 10, 2025
14c8044
remove CheckAndInstallWsh, now replaced by InstallWsh. . reinstall no…
sawka Jan 10, 2025
74c402c
more complicated rtn from tryEnableWsh
sawka Jan 10, 2025
446a93c
swith from term:debugconn to term:conndebug for consistency
sawka Jan 10, 2025
e0ba380
add wshversion to connstatus
sawka Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/server/main-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/wavetermdev/waveterm/pkg/authkey"
"github.com/wavetermdev/waveterm/pkg/blockcontroller"
"github.com/wavetermdev/waveterm/pkg/blocklogger"
"github.com/wavetermdev/waveterm/pkg/filestore"
"github.com/wavetermdev/waveterm/pkg/panichandler"
"github.com/wavetermdev/waveterm/pkg/remote/conncontroller"
Expand Down Expand Up @@ -297,6 +298,7 @@ func main() {
go stdinReadWatch()
go telemetryLoop()
configWatcher()
blocklogger.InitBlockLogger()
webListener, err := web.MakeTCPListener("web")
if err != nil {
log.Printf("error creating web listener: %v\n", err)
Expand Down
18 changes: 15 additions & 3 deletions cmd/wsh/cmd/wshcmd-conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func connReinstallRun(cmd *cobra.Command, args []string) error {
if err := validateConnectionName(connName); err != nil {
return err
}
err := wshclient.ConnReinstallWshCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 60000})
data := wshrpc.ConnExtData{
ConnName: connName,
LogBlockId: RpcContext.BlockId,
}
err := wshclient.ConnReinstallWshCommand(RpcClient, data, &wshrpc.RpcOpts{Timeout: 60000})
if err != nil {
return fmt.Errorf("reinstalling connection: %w", err)
}
Expand Down Expand Up @@ -173,7 +177,11 @@ func connConnectRun(cmd *cobra.Command, args []string) error {
if err := validateConnectionName(connName); err != nil {
return err
}
err := wshclient.ConnConnectCommand(RpcClient, wshrpc.ConnRequest{Host: connName}, &wshrpc.RpcOpts{Timeout: 60000})
data := wshrpc.ConnRequest{
Host: connName,
LogBlockId: RpcContext.BlockId,
}
err := wshclient.ConnConnectCommand(RpcClient, data, &wshrpc.RpcOpts{Timeout: 60000})
if err != nil {
return fmt.Errorf("connecting connection: %w", err)
}
Expand All @@ -186,7 +194,11 @@ func connEnsureRun(cmd *cobra.Command, args []string) error {
if err := validateConnectionName(connName); err != nil {
return err
}
err := wshclient.ConnEnsureCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 60000})
data := wshrpc.ConnExtData{
ConnName: connName,
LogBlockId: RpcContext.BlockId,
}
err := wshclient.ConnEnsureCommand(RpcClient, data, &wshrpc.RpcOpts{Timeout: 60000})
if err != nil {
return fmt.Errorf("ensuring connection: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/wsh/cmd/wshcmd-ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
}
// first, make a connection independent of the block
connOpts := wshrpc.ConnRequest{
Host: sshArg,
Host: sshArg,
LogBlockId: blockId,
Keywords: wshrpc.ConnKeywords{
SshIdentityFile: identityFiles,
},
Expand Down
26 changes: 20 additions & 6 deletions frontend/app/block/blockframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
getSettingsKeyAtom,
getUserName,
globalStore,
refocusNode,
useBlockAtom,
WOS,
} from "@/app/store/global";
import { globalRefocusWithTimeout } from "@/app/store/keymodel";
import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import { ErrorBoundary } from "@/element/errorboundary";
Expand Down Expand Up @@ -356,7 +356,11 @@ const ConnStatusOverlay = React.memo(
}, [width, connStatus, setShowError]);

const handleTryReconnect = React.useCallback(() => {
const prtn = RpcApi.ConnConnectCommand(TabRpcClient, { host: connName }, { timeout: 60000 });
const prtn = RpcApi.ConnConnectCommand(
TabRpcClient,
{ host: connName, logblockid: nodeModel.blockId },
{ timeout: 60000 }
);
prtn.catch((e) => console.log("error reconnecting", connName, e));
}, [connName]);

Expand Down Expand Up @@ -541,7 +545,11 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
const connName = blockData?.meta?.connection;
if (!util.isBlank(connName)) {
console.log("ensure conn", nodeModel.blockId, connName);
RpcApi.ConnEnsureCommand(TabRpcClient, connName, { timeout: 60000 }).catch((e) => {
RpcApi.ConnEnsureCommand(
TabRpcClient,
{ connname: connName, logblockid: nodeModel.blockId },
{ timeout: 60000 }
).catch((e) => {
console.log("error ensuring connection", nodeModel.blockId, connName, e);
});
}
Expand Down Expand Up @@ -691,7 +699,11 @@ const ChangeConnectionBlockModal = React.memo(
meta: { connection: connName, file: newCwd },
});
try {
await RpcApi.ConnEnsureCommand(TabRpcClient, connName, { timeout: 60000 });
await RpcApi.ConnEnsureCommand(
TabRpcClient,
{ connname: connName, logblockid: blockId },
{ timeout: 60000 }
);
} catch (e) {
console.log("error connecting", blockId, connName, e);
}
Expand Down Expand Up @@ -756,7 +768,7 @@ const ChangeConnectionBlockModal = React.memo(
onSelect: async (_: string) => {
const prtn = RpcApi.ConnConnectCommand(
TabRpcClient,
{ host: connStatus.connection },
{ host: connStatus.connection, logblockid: blockId },
{ timeout: 60000 }
);
prtn.catch((e) => console.log("error reconnecting", connStatus.connection, e));
Expand Down Expand Up @@ -879,12 +891,13 @@ const ChangeConnectionBlockModal = React.memo(
} else {
changeConnection(rowItem.value);
globalStore.set(changeConnModalAtom, false);
globalRefocusWithTimeout(10);
}
}
if (keyutil.checkKeyPressed(waveEvent, "Escape")) {
globalStore.set(changeConnModalAtom, false);
setConnSelected("");
refocusNode(blockId);
globalRefocusWithTimeout(10);
return true;
}
if (keyutil.checkKeyPressed(waveEvent, "ArrowUp")) {
Expand Down Expand Up @@ -916,6 +929,7 @@ const ChangeConnectionBlockModal = React.memo(
onSelect={(selected: string) => {
changeConnection(selected);
globalStore.set(changeConnModalAtom, false);
globalRefocusWithTimeout(10);
}}
selectIndex={rowIndex}
autoFocus={isNodeFocused}
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/store/keymodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ function handleCmdI() {
globalRefocus();
}

function globalRefocusWithTimeout(timeoutVal: number) {
setTimeout(() => {
globalRefocus();
}, timeoutVal);
}

function globalRefocus() {
const layoutModel = getLayoutModelForStaticTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
Expand Down Expand Up @@ -403,6 +409,7 @@ export {
getAllGlobalKeyBindings,
getSimpleControlShiftAtom,
globalRefocus,
globalRefocusWithTimeout,
registerControlShiftStateUpdateHandler,
registerElectronReinjectKeyHandler,
registerGlobalKeys,
Expand Down
9 changes: 7 additions & 2 deletions frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RpcApiType {
}

// command "connensure" [call]
ConnEnsureCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
ConnEnsureCommand(client: WshClient, data: ConnExtData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("connensure", data, opts);
}

Expand All @@ -48,7 +48,7 @@ class RpcApiType {
}

// command "connreinstallwsh" [call]
ConnReinstallWshCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
ConnReinstallWshCommand(client: WshClient, data: ConnExtData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("connreinstallwsh", data, opts);
}

Expand All @@ -57,6 +57,11 @@ class RpcApiType {
return client.wshRpcCall("connstatus", null, opts);
}

// command "controllerappendoutput" [call]
ControllerAppendOutputCommand(client: WshClient, data: CommandControllerAppendOutputData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("controllerappendoutput", data, opts);
}

// command "controllerinput" [call]
ControllerInputCommand(client: WshClient, data: CommandBlockInputData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("controllerinput", data, opts);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/view/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class PreviewModel implements ViewModel {
this.connection = atom<Promise<string>>(async (get) => {
const connName = get(this.blockAtom)?.meta?.connection;
try {
await RpcApi.ConnEnsureCommand(TabRpcClient, connName, { timeout: 60000 });
await RpcApi.ConnEnsureCommand(TabRpcClient, { connname: connName }, { timeout: 60000 });
globalStore.set(this.connectionError, "");
} catch (e) {
globalStore.set(this.connectionError, e as string);
Expand Down
39 changes: 39 additions & 0 deletions frontend/app/view/term/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,45 @@ class TermViewModel implements ViewModel {
},
});
}
const debugConn = blockData?.meta?.["term:conndebug"];
fullMenu.push({
label: "Debug Connection",
submenu: [
{
label: "Off",
type: "checkbox",
checked: !debugConn,
click: () => {
RpcApi.SetMetaCommand(TabRpcClient, {
oref: WOS.makeORef("block", this.blockId),
meta: { "term:conndebug": null },
});
},
},
{
label: "Info",
type: "checkbox",
checked: debugConn == "info",
click: () => {
RpcApi.SetMetaCommand(TabRpcClient, {
oref: WOS.makeORef("block", this.blockId),
meta: { "term:conndebug": "info" },
});
},
},
{
label: "Verbose",
type: "checkbox",
checked: debugConn == "debug",
click: () => {
RpcApi.SetMetaCommand(TabRpcClient, {
oref: WOS.makeORef("block", this.blockId),
meta: { "term:conndebug": "debug" },
});
},
},
],
});
return fullMenu;
}
}
Expand Down
17 changes: 17 additions & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ declare global {
view: string;
};

// wshrpc.CommandControllerAppendOutputData
type CommandControllerAppendOutputData = {
blockid: string;
data64: string;
};

// wshrpc.CommandControllerResyncData
type CommandControllerResyncData = {
forcerestart?: boolean;
Expand Down Expand Up @@ -286,11 +292,18 @@ declare global {
metamaptype: MetaType;
};

// wshrpc.ConnExtData
type ConnExtData = {
connname: string;
logblockid?: string;
};

// wshrpc.ConnKeywords
type ConnKeywords = {
"conn:wshenabled"?: boolean;
"conn:askbeforewshinstall"?: boolean;
"conn:overrideconfig"?: boolean;
"conn:wshpath"?: string;
"display:hidden"?: boolean;
"display:order"?: number;
"term:*"?: boolean;
Expand All @@ -317,6 +330,7 @@ declare global {
type ConnRequest = {
host: string;
keywords?: ConnKeywords;
logblockid?: string;
};

// wshrpc.ConnStatus
Expand All @@ -329,6 +343,8 @@ declare global {
activeconnnum: number;
error?: string;
wsherror?: string;
nowshreason?: string;
wshversion?: string;
};

// wshrpc.CpuDataRequest
Expand Down Expand Up @@ -494,6 +510,7 @@ declare global {
"term:vdomtoolbarblockid"?: string;
"term:transparency"?: number;
"term:allowbracketedpaste"?: boolean;
"term:conndebug"?: string;
"web:zoom"?: number;
"web:hidenav"?: boolean;
"markdown:fontsize"?: number;
Expand Down
15 changes: 12 additions & 3 deletions pkg/blockcontroller/blockcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"sync/atomic"
"time"

"github.com/wavetermdev/waveterm/pkg/blocklogger"
"github.com/wavetermdev/waveterm/pkg/filestore"
"github.com/wavetermdev/waveterm/pkg/panichandler"
"github.com/wavetermdev/waveterm/pkg/remote"
Expand Down Expand Up @@ -375,9 +376,7 @@ func (bc *BlockController) setupAndStartShellProcess(rc *RunShellOpts, blockMeta
} else {
shellProc, err = shellexec.StartRemoteShellProc(rc.TermSize, cmdStr, cmdOpts, conn)
if err != nil {
conn.WithLock(func() {
conn.WshError = err.Error()
})
conn.SetWshError(err)
conn.WshEnabled.Store(false)
log.Printf("error starting remote shell proc with wsh: %v", err)
log.Print("attempting install without wsh")
Expand Down Expand Up @@ -759,6 +758,13 @@ func getOrCreateBlockController(tabId string, blockId string, controllerName str
return bc
}

func formatConnNameForLog(connName string) string {
if connName == "" {
return "local"
}
return connName
}

func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts *waveobj.RuntimeOpts, force bool) error {
if tabId == "" || blockId == "" {
return fmt.Errorf("invalid tabId or blockId passed to ResyncController")
Expand All @@ -769,6 +775,7 @@ func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts
}
if force {
StopBlockController(blockId)
time.Sleep(100 * time.Millisecond) // TODO see if we can remove this (the "process finished with exit code" message comes out after we start reconnecting otherwise)
}
connName := blockData.Meta.GetString(waveobj.MetaKey_Connection, "")
controllerName := blockData.Meta.GetString(waveobj.MetaKey_Controller, "")
Expand All @@ -784,8 +791,10 @@ func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts
if curBc != nil {
bcStatus := curBc.GetRuntimeStatus()
if bcStatus.ShellProcStatus == Status_Running && bcStatus.ShellProcConnName != connName {
blocklogger.Infof(ctx, "\n[conndebug] stopping blockcontroller due to conn change %q => %q\n", formatConnNameForLog(bcStatus.ShellProcConnName), formatConnNameForLog(connName))
log.Printf("stopping blockcontroller %s due to conn change\n", blockId)
StopBlockControllerAndSetStatus(blockId, Status_Init)
time.Sleep(100 * time.Millisecond) // TODO see if we can remove this (the "process finished with exit code" message comes out after we start reconnecting otherwise)
}
}
// now if there is a conn, ensure it is connected
Expand Down
Loading
Loading