-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Describe the bug
It seems like there is a type mismatch between the State of the init callback and the CbInitArg of the start_link function in the ssh_client_channel module.
The init callback defines the received Args as a term()
otp/lib/ssh/src/ssh_client_channel.erl
Lines 76 to 78 in 1621565
| -callback init(Args :: term()) -> | |
| {ok, State :: term()} | {ok, State :: term(), timeout() | hibernate} | | |
| {stop, Reason :: term()} | ignore. |
whereas the
CbInitArg type from the start_link function is [term()]otp/lib/ssh/src/ssh_client_channel.erl
Lines 308 to 315 in 1621565
| -spec start_link(SshConnection, ChannelId, ChannelCb, CbInitArgs) -> | |
| {ok, ChannelRef} | {error, Reason :: term()} | |
| when | |
| SshConnection :: ssh:connection_ref(), | |
| ChannelId :: ssh:channel_id(), | |
| ChannelCb :: atom(), | |
| CbInitArgs :: [term()], | |
| ChannelRef :: pid(). |
After looking around the start function also defines CbInitArg as [term()]
otp/lib/ssh/src/ssh_client_channel.erl
Lines 282 to 289 in 1621565
| -spec start(SshConnection, ChannelId, ChannelCb, CbInitArgs) -> | |
| {ok, ChannelRef} | {error, Reason :: term()} | |
| when | |
| SshConnection :: ssh:connection_ref(), | |
| ChannelId :: ssh:channel_id(), | |
| ChannelCb :: atom(), | |
| CbInitArgs :: [term()], | |
| ChannelRef :: pid(). |
This makes Dialyzer yield a warning when using :ssh_client_channel.start_link with something else then a list of term. For instance when passing am empty map:
The function call will not succeed.
:ssh_client_channel.start_link(
_ssh_connection :: any(),
_channel_id :: any(),
Ssh.ClientChannel,
_init_arg :: %{}
)
breaks the contract
(sshConnection, channelId, channelCb, cbInitArgs) ::
{:ok, :ChannelRef} | {:error, Reason :: term()}
when sshConnection: :ssh.connection_ref(),
channelId: :ssh.channel_id(),
channelCb: atom(),
cbInitArgs: [term()],
channelRef: pid()
To Reproduce
Call :ssh_client_channel.start_link/4 with a map
{:ok, connection_ref} = :ssh.connect('example.com', 22, [user: 'user'], 5000)
{:ok, channel_id} = :ssh_connection.session_channel(connection_ref, 5000)
:ssh_client_channel.start_link(connection_ref, channel_id, :placeholder_mod, #{})Expected behavior
I think the type of CbInitArgs should be term() instead of [term()].
Affected versions
Since it was introduced in OTP 21.