Skip to content

Commit 3207a34

Browse files
committed
Merge pull request #33 from unihorn/42
fix(dbus): avoid jobListener jobs leakage
2 parents 963cd54 + 5cab33b commit 3207a34

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

dbus/methods.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (c *Conn) jobComplete(signal *dbus.Signal) {
3535
out, ok := c.jobListener.jobs[job]
3636
if ok {
3737
out <- result
38+
delete(c.jobListener.jobs, job)
3839
}
3940
c.jobListener.Unlock()
4041
}

dbus/methods_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ func setupUnit(target string, conn *Conn, t *testing.T) {
5050
fixture := []string{abs}
5151

5252
install, changes, err := conn.EnableUnitFiles(fixture, true, true)
53+
if err != nil {
54+
t.Fatal(err)
55+
}
5356

5457
if install != false {
5558
t.Fatal("Install was true")
5659
}
5760

5861
if len(changes) < 1 {
59-
t.Fatal("Expected one change, got %v", changes)
62+
t.Fatalf("Expected one change, got %v", changes)
6063
}
6164

6265
if changes[0].Filename != targetRun {
@@ -211,3 +214,27 @@ func TestStartStopTransientUnit(t *testing.T) {
211214
t.Fatalf("Test unit found in list, should be stopped")
212215
}
213216
}
217+
218+
func TestConnJobListener(t *testing.T) {
219+
target := "start-stop.service"
220+
conn := setupConn(t)
221+
222+
setupUnit(target, conn, t)
223+
224+
jobSize := len(conn.jobListener.jobs)
225+
226+
_, err := conn.StartUnit(target, "replace")
227+
if err != nil {
228+
t.Fatal(err)
229+
}
230+
231+
_, err = conn.StopUnit(target, "replace")
232+
if err != nil {
233+
t.Fatal(err)
234+
}
235+
236+
currentJobSize := len(conn.jobListener.jobs)
237+
if jobSize != currentJobSize {
238+
t.Fatal("JobListener jobs leaked")
239+
}
240+
}

0 commit comments

Comments
 (0)