Skip to content

RefreshPorts code path doesn't really make sense #509

Open

Description

Description

Someone shared this error log for gh cs ssh (used to connect to GitHub codespaces over ssh):

kex_exchange_identification: read: Connection reset by peer
Connection reset by 127.0.0.1 port 65225
tunnel closed: error forwarding port: refresh ports failed: failed to refresh ports: %!w(<nil>)

Looking at the code where this error is returned, there doesn't appear to be any case in which the error will be non-nil:

res, _, err := c.ssh.SendSessionRequest("RefreshPorts", true, make([]byte, 0))
if err != nil {
return fmt.Errorf("failed to send port refresh message: %w", err)
}
if !res {
return fmt.Errorf("failed to refresh ports: %w", err)
}
return err
}

I have no opinion on what the message should say. Happy to open a PR with your recommendation.


Separately, as a minor nit reading this code, it seems like it would be better for the final return on this method to be return nil, since again, no other value is possible.

Activity

  1. williammartin commented on Jan 21, 2025

    @williammartin
    ContributorAuthor

    In looking at the SSH spec, a false boolean return seems to be an occurrence of the server sending SSH_MSG_REQUEST_FAILURE, which happens when "If the recipient does not recognize or support the request"

    https://datatracker.ietf.org/doc/html/rfc4254#section-9

    So I suspect this should really say something like:

     	if !res { 
     		return errors.New("failed to refresh ports: server did not recognise or support the request") 
     	} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions