Shutting down Ranch in a controlled way when an application stops

  • Antony Pinchbeck
  • 2018-10-03
  • Elixir
  • Ranch

Whilst working on a project using Ranch as the underlying transport layer, we noticed that shutting down the application in production could take a significant amount of time.

At application exit the rannch listeners were being killed and then restarted. This is by design as the listeners were just being killed. Supervision at its best.

After a bit of digging, I found that an Application module supports both

prep_stop(state)

and

stop()

functions.

According to the Ranch documentation, to perform an orderly shutdown you need to call

:ranch.stop_listener(listener)

The end result was to use the prep_stop calling the stop_listener for each of the listeners in the application.

© 2001 - 2024 Component X Software Limited All rights reserved.

2020-11-04