Skip to content

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

@j-licht

Description

@j-licht

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions