Resolving Signature Issues with Map Key Ordering in Elixir

201
clicks
Resolving Signature Issues with Map Key Ordering in Elixir

Source: richardtaylor.dev

Type: Post

Richard Taylor encountered a challenging problem where videos failed to load in a project post-OTP 26 upgrade due to changes in map keys sorting. While the issue was not evident in Review and Production or among other developers, it impacted his work. After thorough investigation, it became apparent that the OTP 26 release changed the internal sort order of atom keys in maps, leading to unpredictable and varying order on different Erlang VM invocations. This alteration affected the 'cloudfront-signer' library used in Taylor's project, which relied on the previous, consistent order of map keys when converting Elixir maps to JSON using the Poison library. The root of the issue was the incorrect order of JSON keys after encoding, which resulted in an invalid video URL signature. The solution to this conundrum was switching to the Jason JSON library instead of Poison, restoring the correct key order and solving the signature problem.

© HashMerge 2024