returns (connect-error)
(ctx context.Context, connFlags *wconfig.ConnKeywords)
| 951 | |
| 952 | // returns (connect-error) |
| 953 | func (conn *SSHConn) connectInternal(ctx context.Context, connFlags *wconfig.ConnKeywords) error { |
| 954 | conn.Infof(ctx, "connectInternal %s\n", conn.GetName()) |
| 955 | client, _, err := remote.ConnectToClient(ctx, conn.Opts, nil, 0, connFlags) |
| 956 | if err != nil { |
| 957 | conn.Infof(ctx, "ERROR ConnectToClient: %s\n", remote.SimpleMessageFromPossibleConnectionError(err)) |
| 958 | log.Printf("error: failed to connect to client %s: %s\n", conn.GetName(), err) |
| 959 | return err |
| 960 | } |
| 961 | conn.WithLock(func() { |
| 962 | if conn.Monitor != nil { |
| 963 | conn.Monitor.Close() |
| 964 | conn.Monitor = nil |
| 965 | } |
| 966 | conn.Client = client |
| 967 | conn.ConnHealthStatus = ConnHealthStatus_Good |
| 968 | conn.Monitor = MakeConnMonitor(conn, client) |
| 969 | }) |
| 970 | go func() { |
| 971 | defer func() { |
| 972 | panichandler.PanicHandler("conncontroller:waitForDisconnect", recover()) |
| 973 | }() |
| 974 | conn.waitForDisconnect() |
| 975 | }() |
| 976 | fmtAddr := knownhosts.Normalize(fmt.Sprintf("%s@%s", client.User(), client.RemoteAddr().String())) |
| 977 | conn.Infof(ctx, "normalized knownhosts address: %s\n", fmtAddr) |
| 978 | clientDisplayName := fmt.Sprintf("%s (%s)", conn.GetName(), fmtAddr) |
| 979 | wshResult := conn.tryEnableWsh(ctx, clientDisplayName) |
| 980 | if !wshResult.WshEnabled { |
| 981 | if wshResult.WshError != nil { |
| 982 | conn.Infof(ctx, "ERROR enabling wsh: %v\n", wshResult.WshError) |
| 983 | conn.Infof(ctx, "will connect with wsh disabled\n") |
| 984 | } else { |
| 985 | conn.Infof(ctx, "wsh not enabled: %s\n", wshResult.NoWshReason) |
| 986 | } |
| 987 | telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{ |
| 988 | Event: "conn:nowsh", |
| 989 | Props: telemetrydata.TEventProps{ |
| 990 | ConnType: "ssh", |
| 991 | ConnWshErrorCode: wshResult.NoWshCode, |
| 992 | }, |
| 993 | }) |
| 994 | } |
| 995 | conn.persistWshInstalled(ctx, wshResult) |
| 996 | return nil |
| 997 | } |
| 998 | |
| 999 | func (conn *SSHConn) waitForDisconnect() { |
| 1000 | defer conn.FireConnChangeEvent() |
no test coverage detected