jlouis / turtle

A wrapper on the RabbitMQ Erlang Client (Erlang)
Other
71 stars 15 forks source link

Termination and restarts do not work as expected #45

Closed bajankristof closed 3 years ago

bajankristof commented 4 years ago

It seems like terminating a subscriber pool and then later restarting it does not work as expected.

What I mean:

supervisor:start_child(
    test_sup,
    turtle_service:child_spec(#{ name => test_consumer, ... })
).

1)

At some point I want to terminate the consumer:

supervisor:terminate_child(test_sup, test_consumer).

☝️ this sometimes causes the whole application to crash (I believe because turtle or the underlying amqp module is trying to send a message to a process that doesn't exist anymore, but I haven't been able to reliably reproduce this).

2)

Later I want to restart it, so I call:

supervisor:restart_child(test_sup, test_consumer).

This is what consistently fails even though it looks like everything's working fine. In the console I can see that the supervisor indeed restarted the pool:

18:18:01.519 [debug] Supervisor {<0.2850.0>,amqp_channel_sup} started amqp_gen_consumer:start_link(amqp_selective_consumer, [], {<<"client 127.0.0.1:63499 -> 127.0.0.1:5672">>,11}) at pid <0.2852.0>
pid=<0.2850.0>
18:18:01.519 [debug] Supervisor {<0.2850.0>,amqp_channel_sup} started amqp_channel:start_link(network, <0.2691.0>, 11, <0.2852.0>, {<<"client 127.0.0.1:63499 -> 127.0.0.1:5672">>,11}) at pid <0.2853.0>
pid=<0.2850.0>
18:18:01.520 [debug] Supervisor {<0.2850.0>,amqp_channel_sup} started rabbit_writer:start_link(#Port<0.386>, 11, 131072, rabbit_framing_amqp_0_9_1, <0.2853.0>, {<<"client 127.0.0.1:63499 -> 127.0.0.1:5672">>,11}) at pid <0.2854.0>
pid=<0.2850.0>

even the rabbitmq management page shows that there are unacked messages, but my worker's loop function is not being called anymore.

I understand that the child spec that turtle service returns starts a supervisor but that shouldn't have any effect on the above.

Or am I completely off track and this is not how I'm supposed to do things like this?