From 0644aa390694aa7c0de35fe6c4e6d153e7d70e4d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 16 Nov 2022 21:38:32 +0100 Subject: [PATCH] cli/compose/types: UlimitsConfig.MarshalYAML() fix recursion When marshaling the type with `gopkg.in/yaml.v3`, unmarshaling would recursively call the type's `MarshalYAML()` function, which ultimately resulted in a crash: runtime: goroutine stack exceeds 1000000000-byte limit runtime: sp=0x140202e0430 stack=[0x140202e0000, 0x140402e0000] fatal error: stack overflow This applies a similar fix as was implemented in e7788d6f9a61d67566518efe11e394c414a21173 for the `MarshalJSON()` implementation. An alternative would be to use a type alias (to remove the `MarshalYAML()`), but keeping it simple. Signed-off-by: Sebastiaan van Stijn --- cli/compose/types/types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index 3ebb75d81d..ed2e10e85b 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -441,7 +441,8 @@ func (u *UlimitsConfig) MarshalYAML() (interface{}, error) { if u.Single != 0 { return u.Single, nil } - return u, nil + // Return as a value to avoid re-entering this method and use the default implementation + return *u, nil } // MarshalJSON makes UlimitsConfig implement json.Marshaller