MCPcopy
hub / github.com/wavetermdev/waveterm / Connect

Method Connect

pkg/remote/conncontroller/conncontroller.go:729–824  ·  view source on GitHub ↗

does not return an error since that error is stored inside of SSHConn

(ctx context.Context, connFlags *wconfig.ConnKeywords)

Source from the content-addressed store, hash-verified

727
728// does not return an error since that error is stored inside of SSHConn
729func (conn *SSHConn) Connect(ctx context.Context, connFlags *wconfig.ConnKeywords) error {
730 conn.lifecycleLock.Lock()
731 defer conn.lifecycleLock.Unlock()
732
733 blocklogger.Infof(ctx, "\n")
734 var connectAllowed bool
735 conn.WithLock(func() {
736 if conn.Status == Status_Connecting || conn.Status == Status_Connected {
737 connectAllowed = false
738 } else {
739 conn.Status = Status_Connecting
740 conn.Error = ""
741 connectAllowed = true
742 }
743 })
744 if !connectAllowed {
745 conn.Infof(ctx, "cannot connect to %q when status is %q\n", conn.GetName(), conn.GetStatus())
746 return fmt.Errorf("cannot connect to %q when status is %q", conn.GetName(), conn.GetStatus())
747 }
748 conn.Infof(ctx, "trying to connect to %q...\n", conn.GetName())
749 conn.FireConnChangeEvent()
750 err := conn.connectInternal(ctx, connFlags)
751 if err != nil {
752 errorCode, subCode := remote.ClassifyConnError(err)
753 isContextError := errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
754 conn.Infof(ctx, "ERROR [%s] %v\n\n", errorCode, err)
755 conn.WithLock(func() {
756 conn.Status = Status_Error
757 conn.Error = err.Error()
758 })
759 conn.closeInternal_withlifecyclelock()
760 telemetry.GoUpdateActivityWrap(wshrpc.ActivityUpdate{
761 Conn: map[string]int{"ssh:connecterror": 1},
762 }, "ssh-connconnect")
763 telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{
764 Event: "conn:connecterror",
765 Props: telemetrydata.TEventProps{
766 ConnType: "ssh",
767 ConnErrorCode: errorCode,
768 ConnSubErrorCode: subCode,
769 ConnContextError: isContextError,
770 },
771 })
772 } else {
773 conn.Infof(ctx, "successfully connected (wsh:%v)\n\n", conn.WshEnabled.Load())
774 conn.WithLock(func() {
775 conn.Status = Status_Connected
776 conn.LastConnectTime = time.Now().UnixMilli()
777 if conn.ActiveConnNum == 0 {
778 conn.ActiveConnNum = int(activeConnCounter.Add(1))
779 }
780 })
781 telemetry.GoUpdateActivityWrap(wshrpc.ActivityUpdate{
782 Conn: map[string]int{"ssh:connect": 1},
783 }, "ssh-connconnect")
784 telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{
785 Event: "conn:connect",
786 Props: telemetrydata.TEventProps{

Callers 1

EnsureConnectionFunction · 0.45

Calls 15

WithLockMethod · 0.95
InfofMethod · 0.95
GetNameMethod · 0.95
GetStatusMethod · 0.95
FireConnChangeEventMethod · 0.95
connectInternalMethod · 0.95
getConnectionConfigMethod · 0.95
InfofFunction · 0.92
ClassifyConnErrorFunction · 0.92
GoUpdateActivityWrapFunction · 0.92
GoRecordTEventWrapFunction · 0.92

Tested by

no test coverage detected