diff --git a/packages/library/cozy-lib/templates/_resources.tpl b/packages/library/cozy-lib/templates/_resources.tpl index 9b621fe0d..5830e1400 100644 --- a/packages/library/cozy-lib/templates/_resources.tpl +++ b/packages/library/cozy-lib/templates/_resources.tpl @@ -217,7 +217,7 @@ {{- $limitMiB := div (mul $memoryLimitInt 3) 4194304 }} {{- /* Go accepts 0, and then collects almost without pause. */}} {{- if lt $limitMiB 1 }} -{{- fail (printf "ERROR: a memory limit of %s leaves no room for a Go heap; GOMEMLIMIT needs at least 2Mi." .limits.memory) }} +{{- fail (printf "ERROR: a memory limit of %s leaves no room for a Go heap; GOMEMLIMIT needs a limit of at least 1398102 bytes (4/3 Mi) to come out at 1MiB." .limits.memory) }} {{- end }} {{- printf `%dMiB` $limitMiB }} {{- end }} diff --git a/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_test.yaml b/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_test.yaml index 17a7d0b97..1753f925f 100644 --- a/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_test.yaml +++ b/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_test.yaml @@ -39,15 +39,16 @@ tests: path: data.bareBytes value: "768MiB" - # The smallest limit that still yields a usable value: 75% of 2Mi - # floors to 1MiB. + # The smallest limit that still yields a usable value: 75% of + # 1398102 bytes (4/3 Mi, rounded up) floors to 1MiB. - equal: - path: data.twoMiB + path: data.smallestUsable value: "1MiB" - # Integer division floors, so a limit under 2Mi comes out at 0MiB. Go - # accepts that and then collects almost without pause, slowing the - # component instead of protecting it, so the render stops instead. + # Integer division floors, so a limit one byte under 4/3 Mi comes out + # at 0MiB. Go accepts that and then collects almost without pause, + # slowing the component instead of protecting it, so the render stops + # instead. - it: refuses a limit too small to leave a Go heap values: - resources_gomemlimit_values.yaml @@ -55,7 +56,7 @@ tests: sanitizedResources: belowOneMiB: limits: - memory: "1Mi" + memory: "1398101" asserts: - failedTemplate: errorPattern: "leaves no room for a Go heap" diff --git a/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_values.yaml b/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_values.yaml index 3e367cc21..f6be917e0 100644 --- a/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_values.yaml +++ b/packages/tests/cozy-lib-tests/tests/resources_gomemlimit_values.yaml @@ -11,6 +11,6 @@ sanitizedResources: bareBytes: limits: memory: "1073741824" - twoMiB: + smallestUsable: limits: - memory: "2Mi" + memory: "1398102"