Skip to content

AMQP 1.0 client: gracefully handle connection termination in more places#17013

Merged
mkuratczyk merged 2 commits into
mainfrom
amqp10-client-handle-down
Jul 23, 2026
Merged

AMQP 1.0 client: gracefully handle connection termination in more places#17013
mkuratczyk merged 2 commits into
mainfrom
amqp10-client-handle-down

Conversation

@mkuratczyk

Copy link
Copy Markdown
Contributor

This should address some function_clause errors observed when using AMQP 1.0 shovels.

  reason: {function_clause,
              [{amqp10_client_connection,hdr_sent,
                   [info,
                    {'DOWN',#Ref<0.2037148225.2260205569.233493>,process,
                        <0.29675.0>,normal},
                    {state,0,<0.29672.0>,
                        #Ref<0.2037148225.2260205569.233493>,<0.29676.0>,
                        [{<0.29530.0>,
                          [alias|
                           #Ref<0.0.3779843.2037148225.2260271105.233488>]}],
                        <0.29675.0>,
                        {tcp,#Port<0.396>},
                        undefined,undefined,
                        #{notify => <0.29530.0>,port => 5672,
                          address => "green",
                          sasl =>
                              {encrypted,
                                  <<"6APRufcR3aNjXGKFDynwAyf37GF3YqrJq06ecxGXPXNcdqSEXEKXoitUXhMTLBRhzdnWAQmdu9lw2aZ5TlxChT04sNM7XiCPZVhVFwKI124OLrxsEKjS0zOvYZc8wAlT02XqNHL4HGv9YHRGNX2aFpYCsLVTdEL4yRA8COvRomXsCDuCJ1XpWNvo/Y6fTjkW9PzfZiOwPWyfyvBx2nVCMw==">>},
                          hostname => <<"green">>,
                          properties =>
                              #{<<"ignore-maintenance">> => {boolean,true}},
                          notify_when_opened => <0.29530.0>,
                          notify_when_closed => <0.29530.0>,
                          transfer_limit_margin => 0,
                          max_frame_size => 1048576}}],
                   [{file,"amqp10_client_connection.erl"},{line,244}]},
               {gen_statem,loop_state_callback,11,
                   [{file,"gen_statem.erl"},{line,3735}]},
               {proc_lib,init_p_do_apply,3,
                   [{file,"proc_lib.erl"},{line,329}]}]}
  reason: {function_clause,
               [{amqp10_client_connection,close_sent,
                    [info,
                     {'EXIT',<0.11280.0>,killed},
                     {state,1,<0.11283.0>,
                         #Ref<0.1827165118.3650617346.181159>,<0.11287.0>,[],
                         <0.11285.0>,
                         {tcp,#Port<0.308>},
                         15000,
                         {once,#Ref<0.1827165118.3651141633.134174>},
                         #{notify => <0.11280.0>,port => 5672,
                           address => "green",
                           hostname => <<"green">>,
                           notify_when_opened => <0.11280.0>,
                           notify_when_closed => <0.11280.0>}}],
                    [{file,"amqp10_client_connection.erl"},{line,350}]},
                {gen_statem,loop_state_callback,11,
                    [{file,"gen_statem.erl"},{line,3735}]},
                {proc_lib,init_p_do_apply,3,
                    [{file,"proc_lib.erl"},{line,329}]}]}

When running AMQP 1.0 shovels, sometimes they would crash with errors
like this:

```
  reason: {function_clause,
              [{amqp10_client_connection,hdr_sent,
                   [info,
                    {'DOWN',#Ref<0.2037148225.2260205569.233493>,process,
                        <0.29675.0>,normal},
                    {state,0,<0.29672.0>,
                        #Ref<0.2037148225.2260205569.233493>,<0.29676.0>,
                        [{<0.29530.0>,
                          [alias|
                           #Ref<0.0.3779843.2037148225.2260271105.233488>]}],
                        <0.29675.0>,
                        {tcp,#Port<0.396>},
                        undefined,undefined,
                        #{notify => <0.29530.0>,port => 5672,
                          address => "green",
                          sasl =>
                              {encrypted,
                                  <<"6APRufcR3aNjXGKFDynwAyf37GF3YqrJq06ecxGXPXNcdqSEXEKXoitUXhMTLBRhzdnWAQmdu9lw2aZ5TlxChT04sNM7XiCPZVhVFwKI124OLrxsEKjS0zOvYZc8wAlT02XqNHL4HGv9YHRGNX2aFpYCsLVTdEL4yRA8COvRomXsCDuCJ1XpWNvo/Y6fTjkW9PzfZiOwPWyfyvBx2nVCMw==">>},
                          hostname => <<"green">>,
                          properties =>
                              #{<<"ignore-maintenance">> => {boolean,true}},
                          notify_when_opened => <0.29530.0>,
                          notify_when_closed => <0.29530.0>,
                          transfer_limit_margin => 0,
                          max_frame_size => 1048576}}],
                   [{file,"amqp10_client_connection.erl"},{line,244}]},
               {gen_statem,loop_state_callback,11,
                   [{file,"gen_statem.erl"},{line,3735}]},
               {proc_lib,init_p_do_apply,3,
                   [{file,"proc_lib.erl"},{line,329}]}]}
```
Connections linked by their owner (e.g. AMQP 1.0 shovels call
link/1 on the connection PID) could crash with a function_clause
error if that owner exited with a reason other than shutdown while
the connection was in the close_sent state:

```
  reason: {function_clause,
               [{amqp10_client_connection,close_sent,
                    [info,
                     {'EXIT',<0.11280.0>,killed},
                     {state,1,<0.11283.0>,
                         #Ref<0.1827165118.3650617346.181159>,<0.11287.0>,[],
                         <0.11285.0>,
                         {tcp,#Port<0.308>},
                         15000,
                         {once,#Ref<0.1827165118.3651141633.134174>},
                         #{notify => <0.11280.0>,port => 5672,
                           address => "green",
                           hostname => <<"green">>,
                           notify_when_opened => <0.11280.0>,
                           notify_when_closed => <0.11280.0>}}],
                    [{file,"amqp10_client_connection.erl"},{line,350}]},
                {gen_statem,loop_state_callback,11,
                    [{file,"gen_statem.erl"},{line,3735}]},
                {proc_lib,init_p_do_apply,3,
                    [{file,"proc_lib.erl"},{line,329}]}]}
```

close_sent/3 only matched EXIT signals with reason shutdown or
{shutdown, _}, which is what our own supervisor sends when it wants
us to terminate gracefully within its own timeout. Any other EXIT
reason, such as an owning process being killed, now stops the
connection instead, mirroring how we already give up waiting for a
close frame when the reader process goes down.
@mergify

mergify Bot commented Jul 23, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@mkuratczyk
mkuratczyk merged commit f815505 into main Jul 23, 2026
186 checks passed
@mkuratczyk
mkuratczyk deleted the amqp10-client-handle-down branch July 23, 2026 09:14
mkuratczyk added a commit that referenced this pull request Jul 23, 2026
…ces (#17013) (#17015)

* amqp10_client: handle DOWN in more states

When running AMQP 1.0 shovels, sometimes they would crash with errors
like this:

```
  reason: {function_clause,
              [{amqp10_client_connection,hdr_sent,
                   [info,
                    {'DOWN',#Ref<0.2037148225.2260205569.233493>,process,
                        <0.29675.0>,normal},
                    {state,0,<0.29672.0>,
                        #Ref<0.2037148225.2260205569.233493>,<0.29676.0>,
                        [{<0.29530.0>,
                          [alias|
                           #Ref<0.0.3779843.2037148225.2260271105.233488>]}],
                        <0.29675.0>,
                        {tcp,#Port<0.396>},
                        undefined,undefined,
                        #{notify => <0.29530.0>,port => 5672,
                          address => "green",
                          sasl =>
                              {encrypted,
                                  <<"6APRufcR3aNjXGKFDynwAyf37GF3YqrJq06ecxGXPXNcdqSEXEKXoitUXhMTLBRhzdnWAQmdu9lw2aZ5TlxChT04sNM7XiCPZVhVFwKI124OLrxsEKjS0zOvYZc8wAlT02XqNHL4HGv9YHRGNX2aFpYCsLVTdEL4yRA8COvRomXsCDuCJ1XpWNvo/Y6fTjkW9PzfZiOwPWyfyvBx2nVCMw==">>},
                          hostname => <<"green">>,
                          properties =>
                              #{<<"ignore-maintenance">> => {boolean,true}},
                          notify_when_opened => <0.29530.0>,
                          notify_when_closed => <0.29530.0>,
                          transfer_limit_margin => 0,
                          max_frame_size => 1048576}}],
                   [{file,"amqp10_client_connection.erl"},{line,244}]},
               {gen_statem,loop_state_callback,11,
                   [{file,"gen_statem.erl"},{line,3735}]},
               {proc_lib,init_p_do_apply,3,
                   [{file,"proc_lib.erl"},{line,329}]}]}
```

* amqp10_client: handle unexpected EXIT reasons in close_sent

Connections linked by their owner (e.g. AMQP 1.0 shovels call
link/1 on the connection PID) could crash with a function_clause
error if that owner exited with a reason other than shutdown while
the connection was in the close_sent state:

```
  reason: {function_clause,
               [{amqp10_client_connection,close_sent,
                    [info,
                     {'EXIT',<0.11280.0>,killed},
                     {state,1,<0.11283.0>,
                         #Ref<0.1827165118.3650617346.181159>,<0.11287.0>,[],
                         <0.11285.0>,
                         {tcp,#Port<0.308>},
                         15000,
                         {once,#Ref<0.1827165118.3651141633.134174>},
                         #{notify => <0.11280.0>,port => 5672,
                           address => "green",
                           hostname => <<"green">>,
                           notify_when_opened => <0.11280.0>,
                           notify_when_closed => <0.11280.0>}}],
                    [{file,"amqp10_client_connection.erl"},{line,350}]},
                {gen_statem,loop_state_callback,11,
                    [{file,"gen_statem.erl"},{line,3735}]},
                {proc_lib,init_p_do_apply,3,
                    [{file,"proc_lib.erl"},{line,329}]}]}
```

close_sent/3 only matched EXIT signals with reason shutdown or
{shutdown, _}, which is what our own supervisor sends when it wants
us to terminate gracefully within its own timeout. Any other EXIT
reason, such as an owning process being killed, now stops the
connection instead, mirroring how we already give up waiting for a
close frame when the reader process goes down.

(cherry picked from commit f815505)

Co-authored-by: Michal Kuratczyk <michal.kuratczyk@broadcom.com>
@michaelklishin michaelklishin added this to the 4.4.0 milestone Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants