Skip to content

Commit

Permalink
Fix issue with socket length > 108 due to long task names
Browse files Browse the repository at this point in the history
Ensures that we truncate task names to no more than 60 chars so they
don't exceed the total length limit of 108 that's impose by unix.

Fixes: #395
  • Loading branch information
zph committed Jun 26, 2024
1 parent db06b99 commit d1b98b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ func (d *DAG) SockAddr() string {
h := md5.New()
_, _ = h.Write([]byte(s))
bs := h.Sum(nil)
// Socket name length must be shorter than 108 characters,
// so we truncate the name.
// 108 - 16 (length of the hash) - 34 (length remaining non-name) - 8 padding = 50
lengthLimit := 50
if len(name) > lengthLimit {
name = name[:lengthLimit-1]
}
return path.Join("/tmp", fmt.Sprintf("@dagu-%s-%x.sock", name, bs))
}

Expand Down
6 changes: 6 additions & 0 deletions internal/dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ func TestDAG_SockAddr(t *testing.T) {
d := &DAG{Location: "testdata/testDag.yml"}
require.Regexp(t, `^/tmp/@dagu-testDag-[0-9a-f]+\.sock$`, d.SockAddr())
})
t.Run("Unix Socket", func(t *testing.T) {
d := &DAG{Location: "testdata/testDagVeryLongNameThatExceedsUnixSocketLengthMaximum-testDagVeryLongNameThatExceedsUnixSocketLengthMaximum.yml"}
// 108 is the maximum length of a unix socket address
require.Greater(t, 108, len(d.SockAddr()))
require.Equal(t, "/tmp/@dagu-testDagVeryLongNameThatExceedsUnixSocketLengthMax-b92b711162d6012f025a76d0cf0b40c2.sock", d.SockAddr())
})
}

0 comments on commit d1b98b4

Please sign in to comment.