Skip to content

misc.json_encode_with_kv_lists seemingly incomplete & crashes with mod_matrix_gw #4338

Closed

Description

Image for: Description

Environment

Image for: Environment
  • ejabberd version: 24.12
  • Erlang version: Whatever version comes with default beamPackages… assuming 15.2
  • OS: Linux (NixOS + Nixpkgs unstable 25.05pre)
  • Installed from: Nixpkgs Unstable

Configuration

Image for: Configuration
# relevant parts of a self-hosted single-host setup
hosts:
- toastal.in.th
listen:
- module: ejabberd_http
  port: 8448
  request_handlers:
    /_matrix: mod_matrix_gw
  tls: true
modules:
  mod_matrix_gw:
    host: matrix.@HOST@
    key: MATRIX_SECRET
    key_name: MATRIX_KEY_NAME

Macro data does show up properly in the logs (tho specific values omitted)

Errors from error.log/crash.log

Image for: Errors from error.log/crash.log
2025-01-11 18:34:05.722263+07:00 [error] <0.642.0>@proc_lib:crash_report/4:948 CRASH REPORT:
  crasher:
    initial call: ejabberd_http:init/3
    pid: <0.642.0>
    registered_name: []
    exception error: {unsupported_type,
                         {[{<<"old_verify_keys">>,{[]}},
                           {<<"server_name">>,<<"toastal.in.th">>},
                           {<<"valid_until_ts">>,1737200045721},
                           {<<"verify_keys">>,
                            {[{<<"ed25519:$MATRIX_KEY_NAME">>,
                               {[{<<"key">>,
                                  <<"$MATRIX_SECRET">>}]}}]}}]}}
      in function  json:do_encode/2 (json.erl, line 201)
      in call from misc:json_encode_with_kv_lists/1 (/build/source/src/misc.erl, line 143)
      in call from mod_matrix_gw:sign_json/2 (/build/source/src/mod_matrix_gw.erl, line 722)
      in call from mod_matrix_gw:process/2 (/build/source/src/mod_matrix_gw.erl, line 76)
      in call from ejabberd_http:process/2 (/build/source/src/ejabberd_http.erl, line 378)
      in call from ejabberd_http:process_request/1 (/build/source/src/ejabberd_http.erl, line 508)
      in call from ejabberd_http:process_header/2 (/build/source/src/ejabberd_http.erl, line 297)
      in call from ejabberd_http:parse_headers/1 (/build/source/src/ejabberd_http.erl, line 222)
    ancestors: [ejabberd_http_sup,ejabberd_sup,<0.119.0>]
    message_queue_len: 0
    messages: []
    links: [<0.613.0>,#Port<0.71>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 6772
    stack_size: 29
    reductions: 29939
  neighbours:

2025-01-11 18:34:05.722821+07:00 [error] <0.613.0>@supervisor:do_restart/3:1303 SUPERVISOR REPORT:
    supervisor: {local,ejabberd_http_sup}
    errorContext: child_terminated
    reason: {{unsupported_type,{[{<<"old_verify_keys">>,{[]}},
                                 {<<"server_name">>,<<"toastal.in.th">>},
                                 {<<"valid_until_ts">>,1737200045721},
                                 {<<"verify_keys">>,
                                  {[{<<"ed25519:$KEY_NAME">>,
                                     {[{<<"key">>,
                                        <<"$KEY">>}]}}]}}]}},
             [{json,do_encode,2,[{file,"json.erl"},{line,201}]},
              {misc,json_encode_with_kv_lists,1,
                    [{file,"/build/source/src/misc.erl"},{line,143}]},
              {mod_matrix_gw,sign_json,2,
                             [{file,"/build/source/src/mod_matrix_gw.erl"},
                              {line,722}]},
              {mod_matrix_gw,process,2,
                             [{file,"/build/source/src/mod_matrix_gw.erl"},
                              {line,76}]},
              {ejabberd_http,process,2,
                             [{file,"/build/source/src/ejabberd_http.erl"},
                              {line,378}]},
              {ejabberd_http,process_request,1,
                             [{file,"/build/source/src/ejabberd_http.erl"},
                              {line,508}]},
              {ejabberd_http,process_header,2,
                             [{file,"/build/source/src/ejabberd_http.erl"},
                              {line,297}]},
              {ejabberd_http,parse_headers,1,
                             [{file,"/build/source/src/ejabberd_http.erl"},
                              {line,222}]}]}
    offender: [{pid,<0.642.0>},
               {id,undefined},
               {mfargs,{ejabberd_http,start_link,undefined}},
               {restart_type,temporary},
               {significant,false},
               {shutdown,5000},
               {child_type,worker}]

Bug description

Image for: Bug description

I would assume something in a4fd756 in response to Microsoft GitHub issue #4244 was not properly accounting for the cases required for this. This was supposed to use the built-in JSON encoder which doesn’t handle same amount of structures as jiffy such as tuples. Hopefuly @prefiks can chime in.

Prior to Nixpkgs Unstable jumping to beamPackages27 as the default, this configuration was working, which uses the other branch of code.

1

Footnotes

Image for: Footnotes
  1. Please consider giving up MS GitHub or offering a non-proprietary, non-US-corporate-controlled mirror for this free software project. I wish to delete this Microsoft account in the future, but I need more projects like this to support alternative methods to send patches & contribute.

Metadata

Image for: Metadata

Metadata

Image for: Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Image for: Issue actions