processone / processone/ejabberd

mod_matrix_gw: {unsupported_type} crash on OTP 27 (misc:json_encode_with_kv_lists) still reproduces on 24.12 — follow-up to #4244

Open
#4,602 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component:Matrix
Dominant language
Erlang
Stars
6.7k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Follow-up to the closed #4244 — the OTP-27 json incompatibility in mod_matrix_gw still reproduces on 24.12, so the fix appears incomplete.

Summary

On Erlang/OTP 27, mod_matrix_gw cannot encode any outbound Matrix event: misc:json_encode_with_kv_lists/1 hands OTP 27's native json:encode an EEP-18 / jiffy-style {[{Key,Value},...]} term, which it rejects as {unsupported_type, {[...]}}. Every outbound event (1:1 DM and room messages) dies, so nothing federates. On OTP 26 the same ejabberd works fine (it uses the external JSON library), confirming the trigger is OTP 27's native json module.

Confirmed across versions
ejabberd Erlang/OTP mod_matrix_gw outbound XMPP→Matrix DM
24.12-3+deb13u2 (Debian Trixie) 27.3.4.1 crashes (content_hash/1, mod_matrix_gw.erl:663) never federates
26.7.0 (ProcessOne ejabberd/ecs) 26 (erts 14.2.5) OK delivered to a real @user:remote Matrix account

@toastal reported the same on 24.12 / OTP 27 in #4244, but at sign_json/2 (mod_matrix_gw.erl:722). Both call sites route through misc:json_encode_with_kv_lists/1json:do_encode/2, so the incomplete fix (a4fd756) left the kv-list terms reaching the native encoder.

Repro (24.12 on OTP 27)
  1. mod_matrix_gw enabled, ejabberd_http listener on 8448 with /_matrix, ed25519 key, matrix_id_as_jid: false.
  2. From a local XMPP account, send a chat to someuser%remote.tld@matrix.<vhost>.
  3. Crash:
@mod_matrix_gw_room:handle_event/4:583 failed add_event: {error,
   {unsupported_type,
     {[{<<"auth_events">>,[]},
       {<<"content">>,{[{<<"body">>,<<"...">>},{<<"msgtype">>,<<"m.text">>}]}},
       {<<"depth">>,1}, {<<"origin">>,<<"<vhost>">>}, {<<"origin_server_ts">>,...},
       {<<"prev_events">>,[]}, {<<"room_id">>,<<"!...:<vhost>">>},
       {<<"sender">>,<<"@admin:<vhost>">>}, {<<"type">>,<<"m.room.message">>}]}},
   [{json,do_encode,2,[{file,"json.erl"},{line,201}]},
    {misc,json_encode_with_kv_lists,1,[{file,"misc.erl"},{line,143}]},
    {mod_matrix_gw,content_hash,1,[{file,"mod_matrix_gw.erl"},{line,663}]},
    {mod_matrix_gw_room,add_event,2,[{file,"mod_matrix_gw_room.erl"},{line,1401}]},
    {mod_matrix_gw_room,handle_event,4,[{file,"mod_matrix_gw_room.erl"},{line,579}]}]}
Suggested fix

Make misc:json_encode_with_kv_lists/1 OTP-27-safe for all callers (content_hash/1 and sign_json/2): convert the wrapped-proplist {[{K,V}]} form to maps, or drive json:encode/2 with an encoder callback that handles it. (On OTP < 27 the external library path already works.)

Notes
  • Environment: erlang-p1-xmpp 1.9.4, erlang-p1-tls 1.1.22 (Debian).
  • Downstream impact: Debian Trixie ships 24.12 built against OTP 27, so mod_matrix_gw is non-functional there out of the box; a matching Debian bug will be filed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in misc.erl at json_encode_with_kv_lists/1 and trace its callers in mod_matrix_gw.erl, especially content_hash/1 and sign_json/2; reproduce the OTP 27 failure with the documented Matrix outbound-message steps. Done means outbound events no longer crash on OTP 27 while the existing OTP 26 path remains working.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.