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

Francis Moreau francis.moro at gmail.com
Sun Sep 6 20:23:34 UTC 2020


On Sat, Sep 5, 2020 at 12:18 AM Lennart Poettering
<lennart at poettering.net> wrote:
>
> 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?
>

My service is listening several sockets (which are all pased by
systemd) but depending on user configuration my service may not need
to use all sockets and in this case it would be great if the sockets
not needed stop receiving messages and theirs resources are released.

 I tried to close the socket but nothing seems to happen.

Couldn't systemd react on the socket close and if the service still
runs then it closes the socket until it detects the service is stopped
?

-- 
Francis


More information about the systemd-devel mailing list