What is idiomatic way to signal fx app to stop when server errors #848
-
As titled my question is what is preferred way to notify fx app to stop if I get error from
If I get error from |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@sywhang I am tagging you as I see you did most recent changes. Is there recommended way to do this in fx or this is currently the best way? |
Beta Was this translation helpful? Give feedback.
-
Hi there! Typically, you can use the fx.Shutdowner type to signal that the app should be shut down. This interface is provided to your container by default so you can just add it as a parameter to your provied/invoked function. However, for the case of if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
shutdowner.Shutdown()
} Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi there! Typically, you can use the fx.Shutdowner type to signal that the app should be shut down. This interface is provided to your container by default so you can just add it as a parameter to your provied/invoked function.
However, for the case of
net/http.Server
, note that per the documentation thatSever.ListenAndServe
always returns a non-nil error—even if you calledShutdown
orClose
. So you probably want to ignore ErrServerClosed:Hope this helps!