[systemd-devel] Why systemd keeps references on passed sockets ?

Lennart Poettering lennart at poettering.net
Fri Sep 4 22:18:23 UTC 2020


On Fr, 04.09.20 21:53, Francis Moreau (francis.moro at gmail.com) wrote:

> Hi,
>
> I have a service which is activated by a socket unit. When systemd
> passes the (netlink) socket to my service it seems that it still keeps
> a reference on the socket, at least ss(8) showed this.
>
> Is this expected ? If yes can this be prevented ?
>
> I'm asking because my service may not need the socket in some cases
> hence it closes it but systemd keeps it open and the socket keeps
> receiving messages and consuming memory for nothing.

It's how socket activation works really (at least with Accept=no): pid
1 allocate the socket and activates your service every time something
happens on it, except if your service is already running. Thus a
service can auto-start, process one or more events on it, can exit
when idle, or even crash, it doesn't matter, no traffic is lost
(except the very datagram it was processing or the connection that it
was handling when it crashed), and as soon as POLLIN is seen on the
socket again the service is started again can continue where it left
off.

You are apparently looking for a different model? i.e. where automatic
restart and exit-on-idle do not exist? A model like that is currently
not implemented. Can you elaborate on the usecase?

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list