Skip to content

Commit d1b7722

Browse files
authored
Fix non-deterministic compile-time code (#646)
The BEAM files for these two modules would change when compiled even though their corresponding source files were the same. This was due to maps having an unspecified traversal order. Sorting the map entries or keys makes their compilation deterministic. This helps Nerves minimize the number of changes that need to be sent over the wire for delta firmware updates.
1 parent 245a5e8 commit d1b7722

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

lib/bandit.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ defmodule Bandit do
262262
@thousand_island_keys ThousandIsland.ServerConfig.__struct__()
263263
|> Map.from_struct()
264264
|> Map.keys()
265+
|> Enum.sort()
265266

266267
@doc """
267268
Starts a Bandit server using the provided arguments. See `t:options/0` for specific options to

lib/bandit/http2/errors.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule Bandit.HTTP2.Errors do
3838

3939
@spec to_reason(integer()) :: atom()
4040

41-
for {name, value} <- error_codes do
41+
for {name, value} <- Enum.sort(error_codes) do
4242
@spec unquote(name)() :: unquote(Macro.var(name, Elixir)) :: unquote(value)
4343
def unquote(name)(), do: unquote(value)
4444

0 commit comments

Comments
 (0)