This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-31
Channels
- # architecture (1)
- # babashka (17)
- # calva (18)
- # cider (5)
- # clj-kondo (5)
- # cljdoc (44)
- # cljs-dev (2)
- # clojure (49)
- # clojure-europe (11)
- # clojure-norway (16)
- # clojure-uk (3)
- # clojurescript (89)
- # clr (8)
- # conjure (7)
- # cursive (26)
- # data-science (2)
- # datomic (15)
- # emacs (11)
- # events (1)
- # fulcro (8)
- # gratitude (3)
- # hyperfiddle (68)
- # introduce-yourself (1)
- # london-clojurians (1)
- # lsp (3)
- # nbb (8)
- # pathom (44)
- # pedestal (14)
- # polylith (2)
- # random (1)
- # shadow-cljs (8)
- # spacemacs (13)
- # squint (36)
- # tools-deps (9)
- # xtdb (17)
How can I configure Pedestal to prevent active HTTP connections from being terminated during shutdown? Any suggestions would be greatly appreciated.
i'm surprised jetty does no perform a graceful shutdown by default. You could try setting the stopTimeout
(setStopTimeout here: https://github.com/pedestal/pedestal/blob/9b02e4c4a9b87c718ed7f3f7bcdab032e84336a7/jetty/src/io/pedestal/http/jetty.clj#L195) to see if that helps ?
https://eclipse.dev/jetty/documentation/jetty-9/index.html#jetty-connectors
To perform a graceful shutdown of Jetty, the stats
https://eclipse.dev/jetty/documentation/jetty-9/index.html#startup-modules must be enabled
apparently you need both the stats module and a positive value for stopTimeout (and a recent version of jetty 9.4)
stopTimeout should be 30s by default, so maybe just adding the stats module would fix the issue ? (it's hard to distinguish what applies to the embedded version or to the application version, seems like it's null by default)
edit: from the doc
// === jetty-stats.xml ===
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
server.setHandler(stats);
server.addBeanToAllConnectors(new ConnectionStatistics());
Thanks @U02F0C62TC1 I will try this
I tried it and simply adding stats made it work. So no need to set stopTimeout if the default value is good enough for you
(defn add-stats
[m]
(let [^org.eclipse.jetty.server.Server server (::server/server m)
stats (new org.eclipse.jetty.server.handler.StatisticsHandler)]
(.setHandler stats (.getHandler server))
(.setHandler server stats)
m))
also: I did not manage to make the stopTimeout value work so I don't know how to properly set it. Or maybe it can't be lower than other timeout values (connection, socket, etc)
perhaps it will be clearer jetty 10/11
(i tried to set it on the ServerConnector
instances in create-server, no errors but my server did not stop early if I set a low timeout value, it still waited for my handler to respond)
from the pedestal-service template:
(-> [...]
server/create-server
add-stats
server/start)
I did manage to increase or decrease timeout @U02F0C62TC1
(defn add-stats
[{:keys [::server/server] :as service-map}]
(let [stats (StatisticsHandler.)]
(.setStopTimeout server 20000)
(.setHandler stats (.getHandler server))
(.setHandler server stats)
service-map))
The statistic handler can be also configured via container-options
like
(defn jetty-configurator
"Add statistics handler in Jetty server via `container-options` of the
pedestal."
[server]
(let [stats (StatisticsHandler.)]
(.setStopTimeout server 60000)
(.setHandler stats (.getHandler server))
(.setHandler server stats))
server)
And from pedestal-service template:
(-> service-map
(assoc ::http/container-options {:configurator jetty-configurator})
http/create-server
http/start)