garden-io / garden

Automation for Kubernetes development and testing. Spin up production-like environments for development, testing, and CI on demand. Use the same configuration and workflows at every step of the process. Speed up your builds and test runs via shared result caching
https://garden.io
Mozilla Public License 2.0
3.33k stars 270 forks source link

JS out of memory error when using bad templating format #749

Closed bfosberry closed 5 years ago

bfosberry commented 5 years ago

Bug

When a bad template string is used it can cause a Javascript head out of memory error

Current Behavior

Using a template string without a fulfilled "OR" clause will cause an OOM:

Correct format would be something like

        AWS_ACCESS_KEY_ID: "${local.env.AWS_ACCESS_KEY_ID|| \"default\" }"

But if you pass in

        AWS_ACCESS_KEY_ID: "${local.env.AWS_ACCESS_KEY_ID|| }"

This results in an OOM and stacktrace:


<--- Last few GCs --->

[25142:0x102600000]    38002 ms: Scavenge 1202.4 (1438.0) -> 1188.9 (1441.0) MB, 6.4 / 0.0 ms  (average mu = 0.138, current mu = 0.048) allocation failure
[25142:0x102600000]    39224 ms: Mark-sweep 1203.8 (1441.0) -> 1189.2 (1438.0) MB, 1193.5 / 0.0 ms  (average mu = 0.097, current mu = 0.050) allocation failure scavenge might not succeed
[25142:0x102600000]    39263 ms: Scavenge 1204.4 (1438.0) -> 1190.7 (1441.0) MB, 7.0 / 0.0 ms  (average mu = 0.097, current mu = 0.050) allocation failure

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x3fa871e841bd]
Security context: 0xdf16c21e589 <JSObject>
    1: peg$parsePrefix(aka peg$parsePrefix) [0xdf1a7e44a31] [/snapshot/project/garden-service/tmp/dist/build/template-string-parser.js:~1546] [pc=0x3fa871f4810d](this=0xdf1807022e1 <undefined>)
    2: peg$parseNestedTemplateString(aka peg$parseNestedTemplateString) [0xdf1a7e446b1] [/snapshot/project/garden-service/tmp/dist/build/template-string-parser.js:~481...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/garden]
 2: node::OnFatalError(char const*, char const*) [/usr/local/bin/garden]
 3: v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/garden]
 4: v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/garden]
 5: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/garden]
 6: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/garden]
 7: v8::internal::Heap::AllocateRawWithRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/garden]
 8: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/garden]
 9: v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/garden]
10: 0x3fa871e841bd
11: 0x3fa871f4810d
12: 0x3fa871f62870
Abort trap: 6

Expected behavior

Either garden accepts this as a parameter, or validates to ensure the bad syntax fails early.

Reproducible example

brendan.fosberry$ cat garden.yml
module:
  name: test
  description: Test
  type: container
  env:
    TEST_PARAM: "${local.env.FOO|| }" # it errors with and without quotes here

Workaround

I could use valid template strings

Suggested solution(s)

Validate for bad syntax in the string templating

Additional context

Seems like its some kind of recursive loop within the code, perhaps searching for something to fill the template with

Your environment

Running garden dev locally on OSX

garden version 0.9.11 kubectl version

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-26T00:04:52Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

docker version

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:39 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     true
edvald commented 5 years ago

Ah yes, this is addressed by #743 which will be in our next release.

bfosberry commented 5 years ago

Nice, that looks very relevant, closing this bug report, thank you!