Socket Activation #4444
-
Just wondering if anyone has any experience with socket activation via systemd (Linux) or launchd (macOS)? I have not tested the following yet, but I think it will work. Any thoughts or notes? If I'm correct, you can't pass an const fastify = Fastify({
/**
* Example to use socket activation, via file descriptor via something like
* https://github.com/sorccu/node-socket-activation
*/
serverFactory(handler, opts: FastifyServerOptions) {
const server = http.createServer(handler);
// const coreListen = server.listen as net.Server["listen"]; // overload 7
const coreListen = server.listen as (...args: any[]) => Http.Server;
Object.assign(server, {
listen(options: net.ListenOptions, cb?: () => void) {
const fd = 3; // TODO: Get fd from socket-activation lib...
if (options.backlog) {
coreListen.call(server, { fd }, options.backlog, cb);
} else {
coreListen.call(server, { fd }, cb);
}
return server;
},
});
return server;
},
// ...
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Never tried Line 305 in c068697 That being said, at the given state you'll need to pass through the closure of the |
Beta Was this translation helpful? Give feedback.
Never tried
socket-activation
before (but thanks for the item to my reading list though). Butfastify
sanitizes thelisten
arguments before calling theserverFactory
(either custom or the HTTP one from Node). See reference:fastify/lib/server.js
Line 305 in c068697
That being said, at the given state you'll need to pass through the closure of the
listen
method, thefd
to forward it.Not sure why
fastify
doesn't support it, but most likely due to security concerns 🙂