From a5484be9f340c5e6f4fb89edd51fccc63421e103 Mon Sep 17 00:00:00 2001 From: Zarathustra2 Date: Tue, 29 Mar 2022 20:15:13 +0200 Subject: [PATCH] FIX: Memory leak: Monitor target only once Previously `Process.monitor` had been called in every recursion for the target even though we only need to call it only once. --- lib/httpoison/base.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/httpoison/base.ex b/lib/httpoison/base.ex index 9d67883..953e3cf 100644 --- a/lib/httpoison/base.ex +++ b/lib/httpoison/base.ex @@ -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, @@ -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)})