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: dagu-org#395
  • Loading branch information
zph committed Jun 26, 2024
1 parent db06b99 commit 5b23fe5
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 to 60 characters.
// 108 - 16 (length of the hash) - 32 (length of the prefix) - 2 connectors - 18 safety margin = 40 or 39 with 0 indexing
lengthLimit := 39
if len(name) > lengthLimit {
name = name[:lengthLimit]
}
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-testDagVeryLongNameThatExceedsUnixSocket-b92b711162d6012f025a76d0cf0b40c2.sock", d.SockAddr())
})
}

0 comments on commit 5b23fe5

Please sign in to comment.