Open
Description
- 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")
}