Skip to content

Commit e7138fb

Browse files
author
José Valim
committed
Avoid Mix.ProjectStack deadlock, closes #8024
Signed-off-by: José Valim <[email protected]>
1 parent 04ecc05 commit e7138fb

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

lib/mix/lib/mix/project_stack.ex

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,25 @@ defmodule Mix.ProjectStack do
9999

100100
@spec config_mtime() :: [integer]
101101
def config_mtime() do
102-
get_and_update(fn state ->
103-
get_and_update_in(state.stack, fn
104-
[%{config_mtime: nil, config_files: files} = h | t] ->
105-
mtime = files |> Enum.map(&Mix.Utils.last_modified/1) |> Enum.max()
106-
{mtime, [%{h | config_mtime: mtime} | t]}
102+
mtime_or_files =
103+
get(fn
104+
%{stack: [%{config_mtime: nil, config_files: files} | _]} -> files
105+
%{stack: [%{config_mtime: mtime} | _]} -> mtime
106+
%{stack: []} -> 0
107+
end)
107108

108-
[%{config_mtime: mtime} | _] = stack ->
109-
{mtime, stack}
109+
if is_list(mtime_or_files) do
110+
mtime = mtime_or_files |> Enum.map(&Mix.Utils.last_modified/1) |> Enum.max()
110111

111-
[] ->
112-
{0, []}
112+
cast(fn state ->
113+
update_in(state.stack, fn [h | t] -> [%{h | config_mtime: mtime} | t] end)
113114
end)
114-
end)
115+
116+
mtime
117+
else
118+
mtime = mtime_or_files
119+
mtime
120+
end
115121
end
116122

117123
@spec config_apps() :: [atom]

lib/mix/test/mix/tasks/loadconfig_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ defmodule Mix.Tasks.LoadconfigTest do
6161
Mix.Task.run("loadconfig", [config])
6262
assert config in Mix.Project.config_files()
6363
assert Mix.Project.config_mtime() > mtime
64+
65+
# Touching it should not have any deadlocks
66+
File.touch!(config, {{2030, 1, 1}, {0, 0, 0}})
67+
Mix.Task.run("loadconfig", [config])
68+
assert config in Mix.Project.config_files()
69+
assert Mix.Project.config_mtime() > mtime
6470
end)
6571
end
6672

0 commit comments

Comments
 (0)