Why wont application supervisor restart a task on its own?

I am working through the elixir-lang getting started guide and I am confused why a task assigned to the supervision tree wont restart automatically.

  def start(_type, _args) do
    children = [
      {Task, fn -> KVServer.accept(4040) end}
    ]

    opts = [strategy: :one_for_one, name: KVServer.Supervisor]
    Supervisor.start_link(children, opts)
  end

I see that the next section outlays Task.Supervisor, etc and there are more bits that can restart a task, but should the above not be enough for the main supervisor to see a task crash (do-able here by connecting and disconnecting, no replacement “server” is started) and to just call “start_link” with the child spec?

Further down the page:

However, there is still one concern left, which are the restart strategies. Tasks, by default, have the :restart value set to :temporary, which means they are not restarted. This is an excellent default for the connections started via the Task.Supervisor, as it makes no sense to restart a failed connection, but it is a bad choice for the acceptor. If the acceptor crashes, we want to bring the acceptor up and running again.

Somewhat particular to Task, normal GenServers that you write will behave a bit more as expected.

2 Likes