Skip to content

Commit

Permalink
Return :epipe if command is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Sep 25, 2024
1 parent 9fcb065 commit a77c931
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/ex_cmd/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ defmodule ExCmd.Process do

def handle_call({:write_stdin, binary}, from, state) do
case State.pop_operation(state, :write_stdin) do
_ when state.status != :running ->
{:reply, {:error, :epipe}, state}

{:error, :operation_not_found} ->
case Operations.pending_input(state, from, binary) do
{:noreply, state} ->
Expand Down Expand Up @@ -888,15 +891,16 @@ defmodule ExCmd.Process do
end)
end

@kill_command_buffer_timeout 100

@spec divide_timeout(non_neg_integer) :: {non_neg_integer, non_neg_integer}
defp divide_timeout(timeout) when timeout > @exit_status_buffer_timeout do
timeout = timeout - @exit_status_buffer_timeout

if timeout < 50 do
if timeout < @kill_command_buffer_timeout do
{0, 0}
else
# we need at least 50s
kill_timeout = min(50, timeout - 50)
kill_timeout = min(@kill_command_buffer_timeout, timeout - @kill_command_buffer_timeout)
{timeout - kill_timeout, kill_timeout}
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/ex_cmd/process_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule ExCmd.ProcessTest do
assert {:ok, 0} == Process.await_exit(s, 500)

# wait for the process to terminate
:timer.sleep(100)
:timer.sleep(200)
refute Elixir.Process.alive?(s.pid)
end

Expand All @@ -42,7 +42,7 @@ defmodule ExCmd.ProcessTest do
assert {:ok, 0} == Process.await_exit(s, 200)

# wait for the process to terminate
:timer.sleep(100)
:timer.sleep(200)
refute Elixir.Process.alive?(s.pid)
end

Expand Down

0 comments on commit a77c931

Please sign in to comment.