title: handle_info :DOWN is not called after monitored process dies
body: <p>I am having an issue with <code>Process.monitor/1</code>. My initial use case was to monitor Phoenix Channel and do some cleanup after it dies. However, I didn't manage to set it up in Phoenix and decided to test it out with pure GenServers.</p>
  
  
  
  <p>So, I have a simple <code>GenServer</code> and I want to track when it dies:</p>
  
  <pre class="lang-ex prettyprint-override"><code>defmodule Temp.Server do
    use GenServer
  
    def start_link(_), do: GenServer.start_link(__MODULE__, %{})
  
    def init(args) do
      Temp.Monitor.monitor(self())
      {:ok, args}
    end
  end
  </code></pre>
  
  <p>And another GenServer that monitors:</p>
  
  <pre class="lang-ex prettyprint-override"><code>defmodule Temp.Monitor do
    use GenServer
    require Logger
  
    def start_link(_) do
      GenServer.start_link(__MODULE__, [], name: __MODULE__)
    end
  
    def monitor(pid) do
      Process.monitor(pid)
    end
  
    def handle_info({:DOWN, ref, :process, _, _}, state) do
      Logger.info("DOWN")
  
      {:noreply, state}
    end
  end
  </code></pre>
  
  <p>So, if I understand correctly, <code>Process.monitor</code> will start monitoring the <code>Temp.Server</code> process, and should call the <code>handle_info</code> matching <code>:DOWN</code> when <code>Server</code> process dies. If I try it in <code>iex</code>:</p>
  
  <pre class="lang-ex prettyprint-override"><code>iex&gt; {_, pid} = Temp.Server.start_link([])
  {:ok, #PID&lt;0.23068.3&gt;}                    
  iex&gt; Process.exit(pid, :kill)             
  true     
  </code></pre>
  
  <p>I expect <code>handle_info</code> being called from <code>Monitor</code> module and logging "DOWN", however that doesn't happen. What am I doing wrong? I assume it doesn't work because I call to monitor from Server process <code>Temp.Monitor.monitor(self())</code>, but I just can't figure out how else should I do it.</p>