coreos / coreos/go-systemd

StartUnitContext did not respect context in matter of the jobComplete signal

Open
#428 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.7k
Forks
338
PR merge metrics
No merged PRs in 30d

Description

Conn.StartUnitContext, which actually calls internally startJob uses the given context only for the dbus call but not for the job listener.
https://github.com/coreos/go-systemd/blob/d843340ab4bd3815fda02e648f9b09ae2dc722a7/dbus/methods.go#L61
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dbus/methods.go at Conn.StartUnitContext and its internal startJob call, then inspect how the job listener stores and completes jobs. Verify how context cancellation should remove the listener without leaving entries after the systemd job finishes; the issue does not name a test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.