         {:noreply, state}
     end
   end
+
+  def handle_info({:gen_event_EXIT, _, :normal}, state) do
+    {:noreply, state}
+  end
+  def handle_info({:gen_event_EXIT, _, {:swapped, _, _}}, state) do
+    {:noreply, state}
+  end
+  def handle_info({:gen_event_EXIT, _, :shutdown}, state) do
+    {:noreply, state}
+  end
+  def handle_info({:gen_event_EXIT, handler, _}, %{em: em, handlers: handlers} = state) do
+    args = HashDict.get(handlers, handler)
+    :ok  = GenEvent.add_mon_handler(em, handler, args)
+    {:noreply, state}
+  end
 end

  def init(handlers) do
    retry_ms  = Application.get_env(:discovery, :retry_connect_ms, 5000)
    {:ok, em} = GenEvent.start_link
    Enum.each handlers, fn
      {module, args} ->
        register_handler(em, module, args)
      module when is_atom(module) ->
        register_handler(em, module)
    end
    {:ok, %{retry_ms: retry_ms, timers: %{}, em: em}}
  end

  def handle_call({:add_handler, module, args}, _, %{em: em} = state) do
    case register_handler(em, module, args) do
      {:ok, ref} ->
        {:reply, {:ok, {module, ref}}, state}
      error ->
        {:reply, error, state}
    end


  defp register_handler(em, module, args \\ []) do
    ref = make_ref()
    case GenEvent.add_mon_handler(em, {module, ref}, args) do
      :ok   -> {:ok, ref}
      error -> error
    end
