Skip to content

Wrong type specification inside ssh_client_channel #10351

@Krapaince

Description

@Krapaince

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()

-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()]
-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()]

-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.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:PSAssigned to OTP team PS

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions