Skip to content

Commit

Permalink
Merge pull request #19057 from swordqiu/hotfix/qj-webconsole-open-for…
Browse files Browse the repository at this point in the history
…ward-failure

fix: webconsole ssh open forward failure
  • Loading branch information
zexi authored Dec 20, 2023
2 parents 7ce1332 + 2b58d6f commit bc454e8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/webconsole/session/resolve_sshinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func acquireForward(ctx context.Context, session *mcclient.ClientSession, srvid
lockman.LockRawObject(ctx, "server", srvid)
defer lockman.ReleaseRawObject(ctx, "server", srvid)

addr, port, err := listForward(session, srvid, ip, proto, port)
addr, nport, err := listForward(session, srvid, ip, proto, port)
if err == nil {
return addr, port, nil
return addr, nport, nil
}
if errors.Cause(err) == httperrors.ErrNotFound {
return openForward(session, srvid, ip, proto, port)
Expand Down Expand Up @@ -162,14 +162,15 @@ func listForward(session *mcclient.ClientSession, srvid string, ip string, proto
return "", 0, errors.Wrap(err, "list-forward")
}

infoList := make([]sForwardInfo, 0)
err = jsonItem.Unmarshal(&infoList, "forwards")
if err != nil {
return "", 0, errors.Wrap(err, "Unmarshal forwards")
}

if len(infoList) > 0 {
return infoList[0].ProxyAddr, infoList[0].ProxyPort, nil
if jsonItem.Contains("forwards") {
infoList := make([]sForwardInfo, 0)
err = jsonItem.Unmarshal(&infoList, "forwards")
if err != nil {
return "", 0, errors.Wrap(err, "Unmarshal forwards")
}
if len(infoList) > 0 {
return infoList[0].ProxyAddr, infoList[0].ProxyPort, nil
}
}

return "", 0, errors.Wrap(httperrors.ErrNotFound, "no forwards")
Expand Down

0 comments on commit bc454e8

Please sign in to comment.