Skip to content

Commit

Permalink
FIX: Memory leak: Monitor target only once
Browse files Browse the repository at this point in the history
Previously `Process.monitor` had been called in every recursion
for the target even though we only need to call it only once.
  • Loading branch information
Zarathustra2 authored and edgurgel committed Mar 31, 2022
1 parent 6b6ad05 commit a5484be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/httpoison/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ defmodule HTTPoison.Base do
@doc false
@spec transformer(pid) :: :ok
def transformer(target) do
# Track the target process so we can exit when it dies
Process.monitor(target)

HTTPoison.Base.transformer(
__MODULE__,
target,
Expand Down Expand Up @@ -629,9 +632,6 @@ defmodule HTTPoison.Base do
process_response_headers,
process_response_chunk
) do
# Track the target process so we can exit when it dies
Process.monitor(target)

receive do
{:hackney_response, id, {:status, code, _reason}} ->
send(target, %HTTPoison.AsyncStatus{id: id, code: process_response_status_code.(code)})
Expand Down

0 comments on commit a5484be

Please sign in to comment.