Skip to content

Commit 29d36f2

Browse files
committed
Stop some apps after Mix.install/2
1 parent aaa3a99 commit 29d36f2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/mix/lib/mix.ex

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ defmodule Mix do
715715
consolidate_protocols: Keyword.get(opts, :consolidate_protocols, true)
716716
]
717717

718+
started_apps = Application.started_applications()
718719
:ok = Mix.Local.append_archives()
719720
:ok = Mix.ProjectStack.push(@mix_install_project, config, "nofile")
720721
build_dir = Path.join(dir, "_build")
@@ -729,6 +730,11 @@ defmodule Mix do
729730
end
730731

731732
Mix.Task.rerun("deps.loadpaths")
733+
734+
# Hex and SSL can use a good amount of memory after the registry fetching,
735+
# so we stop any app started during deps resolution.
736+
stop_apps(Application.started_applications() -- started_apps)
737+
732738
Mix.Task.rerun("compile")
733739
end)
734740

@@ -743,6 +749,33 @@ defmodule Mix do
743749
end
744750
end
745751

752+
defp stop_apps([]), do: :ok
753+
754+
defp stop_apps(apps) do
755+
:logger.add_primary_filter(:silence_app_exit, {&silence_app_exit/2, []})
756+
Enum.each(apps, fn {app, _, _} -> Application.stop(app) end)
757+
:logger.remove_primary_filter(:silence_app_exit)
758+
:ok
759+
end
760+
761+
defp silence_app_exit(
762+
%{
763+
msg:
764+
{:report,
765+
%{
766+
label: {:application_controller, :exit},
767+
report: [application: _, exited: :stopped] ++ _
768+
}}
769+
},
770+
_extra
771+
) do
772+
:stop
773+
end
774+
775+
defp silence_app_exit(_message, _extra) do
776+
:ignore
777+
end
778+
746779
defp maybe_expand_path_dep(opts) do
747780
if Keyword.has_key?(opts, :path) do
748781
Keyword.update!(opts, :path, &Path.expand/1)

0 commit comments

Comments
 (0)