Skip to content

Match error in ssh_sftp:write_file when connection gets closed concurrently #9655

@pguillory

Description

@pguillory

Describe the bug
A match error is sometimes raised in ssh_sftp:write_file when the SSH connection or channel is closed by a separate process.

To Reproduce
Sorry about the Elixir repro code.

{:ok, channel} = :ssh_sftp.start_channel(ssh)

spawn(fn ->
  Process.sleep(50)
  :ssh_sftp.stop_channel(channel)
end)

spawn(fn ->
  :ssh_sftp.write_file(channel, '/tmp/foo', "bar")
end)

The timing matters.

  • With a shorter sleep, write_file returns {error, closed}.
  • With a longer sleep, it returns ok.
  • With just the right sleep, it raises {badmatch, {error, closed}} on line 1079 of ssh_sftp.erl.

Expected behavior
I would expect it to return {error, closed} if the connection/channel becomes closed before the operation completes.

Affected versions
27

Additional context
I suspect that ssh_sftp:read_file has a similar problem. It looks like the actual match error is in the do_handle_call for send_window, and recv_window is almost identical.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugpriority:lowteam: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