         send(child_pid, ref)
         cancel_waiting_timer(files, child_pid)
 
+        discard_down(child_pid)
+        new_files = List.keydelete(files, child_pid, 0)
+
         # Sometimes we may have spurious entries in the waiting list
         # because someone invoked try/rescue UndefinedFunctionError
+        new_waiting = List.keydelete(waiting, child_pid, 1)
+        spawn_workers(queue, spawned - 1, new_waiting, new_files, result, warnings, state)
+
+      {:file_cancel, child_pid} ->
+        cancel_waiting_timer(files, child_pid)
         discard_down(child_pid)
-        new_queue = List.delete(queue, child_pid)
         new_files = List.keydelete(files, child_pid, 0)
-        new_waiting = List.keydelete(waiting, child_pid, 1)
-        spawn_workers(new_queue, spawned - 1, new_waiting, new_files, result, warnings, state)
+        spawn_workers(queue, spawned - 1, waiting, new_files, result, warnings, state)
 
       {:file_error, child_pid, file, {kind, reason, stack}} ->
         print_error(file, kind, reason, stack)

    end
  end

  defp should_spawn?(:require, file),
    do: :elixir_code_server.call({:acquire, file}) == :proceed

  defp should_spawn?(_output, _file),
    do: true

  defp waiting_on_without_definition(waiting, pid) do
    {_, ^pid, _, on, _, _} = entry = List.keyfind(waiting, pid, 1)


        send(child, {ref, :ack})

        available =
          for {:module, _, ref, ^module, _defining, _deadlock?} <- waiting,
              do: {ref, :found}

        cancel_waiting_timer(files, child)
        result = [{:module, module} | result]
        spawn_workers(available ++ queue, spawned, waiting, files, result, warnings, state)

