混合版本 "start_iex" 显示错误,而 "start" 没有

Mix release "start_iex" shows error while "start" does not

背景

我正在通过 mix release 创建伞式应用程序的发布。但是,即使我可以手动 运行 应用程序,我在启动它时也会遇到一些错误。

mix release

我正在尝试 运行 一个带有 mix release 的应用程序。此命令运行良好,并在 _build/prod/rel/my_app/bin/my_app 中创建了可执行文件。我可以 运行 使用命令 start 这个可执行文件,一切都很好 运行。

但是,如果我使用 start_iex 而不是 start,我会首先收到错误,然后应用 运行 正常:

$ _build/prod/rel/my_app/bin/my_app start_iex
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

*** ERROR: Shell process terminated! (^G to start new job) ***
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

my_app 是一款综合应用。这是保护伞应用程序的 mix.exs 内容:

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [
      apps_path: "apps",
      version: "0.1.0",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      elixir: "~> 1.10",
      releases: releases()
    ]
  end

  defp deps, do: []

  defp releases, do:
    [
      my_app: [
        applications: [
          api: :permanent,
          core: :permanent,
          storage: :permanent
        ]
      ]
    ]
end

问题

  1. 为什么在使用 start_iex 时出现错误,而在使用 start 时却没有?
  2. 为什么start_iex在出错后可以正常工作?

当您启用 shell 历史记录时,这是一个竞争条件。有一份公开报告 here

Because the disk_log is started after the user process, there is a chance for race conditions on shutdown, where disk_log will terminate before group, which will fail to log.

Furthermore, if disk_log terminates BEFORE the shell starts, then the whole shell will fail to start, which will trigger another shell recursively, until the system finally shuts down. This can be reproduced with this command:

$ erl -kernel shell_history true -s init restart