 
   defp maybe_activate_sock(state) do
     if Enum.empty?(state.receiver_queue) do
-      :ok = :inet.setopts(state.sock, [active: :once])
+      case :inet.setopts(state.sock, [active: :once]) do
+        :ok -> { :noreply, state }
+        error -> { :disconnect, error, state }
+      end
+    else
+      { :noreply, state }
     end
   end
 
   defp maybe_deactivate_sock(state) do
     if Enum.empty?(state.receiver_queue) do
-      :ok = :inet.setopts(state.sock, [active: false])
+      case :inet.setopts(state.sock, [active: false]) do
+        :ok -> :ok
+        error -> { :disconnect, error, {:error, :closed}, state }
+      end
+    else
+      :ok
     end
   end
 

  end

  def handle_call({ :execute, command, args, opts }, from, s) do
    maybe_deactivate_sock(s)
    send_and_receive(s, from, command, args, opts)
  end

  def handle_call({ :execute_quiet, _commands }, _from, %State{ sock: nil } = s) do

    receiver_queue = MapSet.delete(state.receiver_queue, client)
    state = %{state | receiver_queue: receiver_queue}
    maybe_activate_sock(state)
  end

  def handle_info(_msg, state) do
