Skip to content

x/crypto/ssh: ssh client hangs on waitting for the openConfirm message. #50604

Open
@ChiWu-Zero

Description

@ChiWu-Zero
  • overview

The hang problem arises when using the library, the ssh client key code in file ssh/mux.go:

open := channelOpenMsg{
	ChanType:         chanType,
	PeersWindow:      ch.myWindow,
	MaxPacketSize:    ch.maxIncomingPayload,
	TypeSpecificData: extra,
	PeersID:          ch.localId,
}
if err := m.sendMessage(open); err != nil {
	return nil, err
}

switch msg := (<-ch.msg).(type) {
case *channelOpenConfirmMsg:
	return ch, nil
case *channelOpenFailureMsg:
	return nil, &OpenChannelError{msg.Reason, msg.Message}
default:
	return nil, fmt.Errorf("ssh: unexpected packet in response to channel open: %T", msg)
}

The process hangs on the line of "switch msg := (<-ch.msg).(type) ",it may loss the OpenConfirm msg because of the sshd server or the net status.
Maybe we should add the timeout when waitting for the confirm msg.

select {
case data := <-ch.msg:
	switch msg := data.(type) {
	case *channelOpenConfirmMsg:
		return ch, nil
	case *channelOpenFailureMsg:
		return nil, &OpenChannelError{msg.Reason, msg.Message}
	default:
		return nil, fmt.Errorf("ssh: unexpected packet in response to channel open: %T", msg)
	}
case <-time.After(aliveTime):
	return nil, fmt.Errorf("ssh: the confirm message maybe lost")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions