Supervisor doesn't restart the process when shutdown

I read an article about OTP Supervisor (OTPスーパバイザ · Elixir School) and I set it like {DiscordBot, restart: :permanent}, but it still not restaring the process. When it crashed, it says [notice] Application discord_bot exited: shutdown, then it still saying its getting ACK after crash.

So why is my supervisor doesn’t restart the app, and is it still running something? Thanks.

Hi, @rikusen0335 :wave:t2: !
Could you please share more of the error, and DiscordBot?

I think the process gets restarted more than 3 times in 5 seconds (defaults for :max_restarts and :max_seconds options see here) Most probably there is an issue somewhere on init. But we need to see what’s going on =)

Thank you for replying!

I cannot show more full of errors due to security reason, but these are like:

09:26:41.734 [error] Task #PID<0.11482.0> started from #PID<0.1542.0> terminating 
** (FunctionClauseError) no function clause matching in ~~

09:26:41.804 [debug] QUERY OK source="account" ~~

09:26:43.023 [error] Task #PID<0.11482.0> started from #PID<0.1542.0> terminating 
** (FunctionClauseError) no function clause matching in ~~

09:26:43.038 [debug] QUERY OK source="account" ~~

09:26:44.258 [error] Task #PID<0.11482.0> started from #PID<0.1542.0> terminating 
** (FunctionClauseError) no function clause matching in ~~

09:26:44.270 [debug] QUERY OK source="account" ~~

09:26:44.278 [error] Task #PID<0.11482.0> started from #PID<0.1542.0> terminating 
** (FunctionClauseError) no function clause matching in ~~

09:26:45.495 [notice] Application discord_bot exited: shutdown

And also code is available here: GitHub - rikusen0335/KintamaStoreBot: ValorantのストアをDiscordで表示するためのBot / A bot which shows Valorant's daily storefront and nightmarket in Discord.

I’d try change :max_restars, thank you for the information too!

It seems like it actually tries to run the same task 3 times and fails to do so because of “redacted” FunctionClauseError… so instead of changing process supervising options - I would rather focus on the error.

Because, I know what cause of the error and I already fixed it, but once if I raise error (raise "Oh no") that crashes app and it’s not restarted after that.

So I want to make it sure it kills the process and make a new one.

I can only speculate, but, on the logs you posted, we can see that the task is getting terminated and recreated by another process #PID<0.1542.0> , and the application gives up and not start, that is because your application depends on the bot process to be up, since you declare it under the main supervisor, at the Application.start/2. The problem I would assume, was coming from the start_link function of the bot module, in that case it would not be recreated because to successfully be monitored and able to restart it need to start properly. So once your start_link function returns and an error occurs, let’s say on a handle_message it will be restarted.

I hope this helps!

Just to make sure this is clear: Supervisors do not restart children indefinitely and are are not meant to do so either. They will give up eventually (details are configurable). So if you put a permanent error in a child process somewhere on your application’s supervision tree it’s expected to crash your application. If that’s not the behaviour you’re looking for you’ll need to look into non permanent children/dynamic supervisors/monitors/….

Thank you, the last message’s way make it much better now. This was really easy way but I forgot about it.

So that means, like, I need to make a monitor to monitoring the bot process as a children of application’s supervisor?

As my recognition, currently application’s supervisor is monitoring the child process which is application consumer, but we need application’s supervisor monitors → the monitor of consumer, and it also monitors → application consumer?

Sorry for the unclear question, but I need to know about it.

Some discussion about restarts and supervisor trees from 2018:

Thank you. I’ll read them