Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartUnitContext did not respect context in matter of the jobComplete signal #428

Open
j-licht opened this issue Oct 12, 2023 · 0 comments

Comments

@j-licht
Copy link

j-licht commented Oct 12, 2023

Conn.StartUnitContext, which actually calls internally startJob uses the given context only for the dbus call but not for the job listener.

err := c.sysobj.CallWithContext(ctx, job, 0, args...).Store(&p)

This call returns nearly immediately in most cases, when dbus and systemd is reachable.
But the jobComplete signal is only received after the system job is finished, which can take more time.

So the jobListener should be removed after the context is finished.
Like this:

if ch != nil {
		c.jobListener.jobs[p] = ch

		go func(ctx context.Context, p dbus.ObjectPath) {
			<-ctx.Done()
			c.jobListener.Lock()
			defer c.jobListener.Unlock()

			_, ok := c.jobListener.jobs[p]
			if !ok {
				return
			}
			fmt.Println("delete job listener after context is done")
			delete(c.jobListener.jobs, dbus.ObjectPath(p))
		}(ctx, p)
	}

But this not ideal, because it creates a go function for each call.

j-licht added a commit to j-licht/go-systemd that referenced this issue Oct 13, 2023
Oberserve the given context from the function e.g. StartUnitContext,
which are using the internal function startJob. If this context is done
remove the job Listener if existing.

Fixes coreos#428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant