question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to call .getStackName on Stack in Java with Node 12.17.0

See original GitHub issue

I am using CDK from a REPL in Clojure (Java). After upgrading Node to 12.17.0 (the latest release of major version 12, which is recommended for use with CDK/JSII), commands start failing due to stream closed error.

Reproduction Steps

  • Install node 12.17.0.
  • Install Clojure (e.g. brew install clojure/tools/clojure).
  • Start a Clojure REPL session with CDK core as a dependency: clj -Sdeps '{:deps {software.amazon.awscdk/core {:mvn/version "1.42.0"}}}'.
  • Evaluate commands in the REPL by pasting them and pressing enter:
    • Load the CDK classes:
    (import software.amazon.awscdk.core.App software.amazon.awscdk.core.Stack$Builder)
    
    • Define a new Stack object as bar
    (def bar (.build (Stack$Builder/create (App.) "foo")))
    
    • Then try to get the name of the stack:
    (.getStackName bar)
    
  • This will throw an exception and shows the abbreviated error log:
Execution error (IOException) at java.lang.ProcessBuilder$NullOutputStream/write (ProcessBuilder.java:442).
Stream closed

Error Log

You can see a detailed stack trace of the last exception by evaluating *e in the REPL:

user=> *e
#error {
 :cause "Stream closed"
 :via
 [{:type software.amazon.jsii.JsiiException
   :message "Unable to send request to jsii-runtime: java.io.IOException: Stream closed"
   :at [software.amazon.jsii.JsiiRuntime requestResponse "JsiiRuntime.java" 103]}
  {:type java.io.IOException
   :message "Stream closed"
   :at [java.lang.ProcessBuilder$NullOutputStream write "ProcessBuilder.java" 442]}]
 :trace
 [[java.lang.ProcessBuilder$NullOutputStream write "ProcessBuilder.java" 442]
  [java.io.OutputStream write "OutputStream.java" 157]
  [java.io.BufferedOutputStream flushBuffer "BufferedOutputStream.java" 81]
  [java.io.BufferedOutputStream flush "BufferedOutputStream.java" 142]
  [sun.nio.cs.StreamEncoder implFlush "StreamEncoder.java" 318]
  [sun.nio.cs.StreamEncoder flush "StreamEncoder.java" 153]
  [java.io.OutputStreamWriter flush "OutputStreamWriter.java" 254]
  [java.io.BufferedWriter flush "BufferedWriter.java" 257]
  [software.amazon.jsii.JsiiRuntime requestResponse "JsiiRuntime.java" 84]
  [software.amazon.jsii.JsiiClient getPropertyValue "JsiiClient.java" 111]
  [software.amazon.jsii.JsiiObject jsiiGet "JsiiObject.java" 240]
  [software.amazon.jsii.JsiiObject jsiiGet "JsiiObject.java" 228]
  [software.amazon.awscdk.core.Stack getStackName "Stack.java" 624]
  [jdk.internal.reflect.NativeMethodAccessorImpl invoke0 "NativeMethodAccessorImpl.java" -2]
  [jdk.internal.reflect.NativeMethodAccessorImpl invoke "NativeMethodAccessorImpl.java" 62]
  [jdk.internal.reflect.DelegatingMethodAccessorImpl invoke "DelegatingMethodAccessorImpl.java" 43]
  [java.lang.reflect.Method invoke "Method.java" 566]
  [clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 167]
  [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 438]
  [user$eval142 invokeStatic "NO_SOURCE_FILE" 1]
  [user$eval142 invoke "NO_SOURCE_FILE" 1]
  [clojure.lang.Compiler eval "Compiler.java" 7177]
  [clojure.lang.Compiler eval "Compiler.java" 7132]
  [clojure.core$eval invokeStatic "core.clj" 3214]
  [clojure.core$eval invoke "core.clj" 3210]
  [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437]
  [clojure.main$repl$fn__9095 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl_opt invokeStatic "main.clj" 522]
  [clojure.main$main invokeStatic "main.clj" 667]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn invoke "RestFn.java" 397]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.RestFn applyTo "RestFn.java" 132]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}

Environment

  • CDK Version: 1.42.0 (build 3b64241)
  • Node Version: 12.17.0
  • CLI Version: aws-cli/2.0.17 Python/3.8.3 Darwin/19.5.0 botocore/2.0.0dev21
  • OS: Catalina 10.15.5
  • Language: EN

Other

  • Running the example above with Node 12.16.3 (the last release before 12.17.0) throws no exception and just works.
  • Note that once the exception is thrown, a new REPL session is needed to be able to use CDK again (CDK is the first software I encountered which exhibits this behavior). You can quit it using ctrl+d.
  • The comment below by @cadnce helped me get this issue clearer. Is seems it is related to the fact that the code runs in a REPL which reads user input after returning. When you paste this entire code snippet into the REPL and press enter it will not throw and correctly returns the name of the stack ("foo"):
(import software.amazon.awscdk.core.App software.amazon.awscdk.core.Stack$Builder)
(let [bar (.build (Stack$Builder/create (App.) "foo"))] (.getStackName bar))
  • Waiting does seem to be related too: introducing a wait of 200ms between creating the Stack and getting its name works:
(import software.amazon.awscdk.core.App software.amazon.awscdk.core.Stack$Builder)
(let [bar (.build (Stack$Builder/create (App.) "foo"))] (Thread/sleep 200) (.getStackName bar))
  • But a wait of 1000ms will throw the exception:
(import software.amazon.awscdk.core.App software.amazon.awscdk.core.Stack$Builder)
(let [bar (.build (Stack$Builder/create (App.) "foo"))] (Thread/sleep 1000) (.getStackName bar))
  • There are known issues when running CDK (or Jsii?) on Node >= 13.x, but so far the recommendation was always to downgrade to 12.x. Now that the latest release of 12.x is apparently also affected, this workaround is problematic since a lot of tooling (e.g. homebrew with versions plugin) doesn’t allow installing a specific minor version.

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vincent-dmcommented, Jun 2, 2020

I did also occasionaly get RangeError: Maximum call stack size exceeded in my own application (and I did mention it in my initial issue description, so you’re not imagining things 😉), but I haven’t been able to reproduce it so I decided to make this issue more focused. So I agree you should probably open a separate issue.

1reaction
shivlakscommented, Jun 2, 2020

adding the jsii label and assigning to @RomainMuller to take a look

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to install java module in NodeJS - Stack Overflow
I think the problem is with node-gyp command. Try installing the latest version of node-gyp. First go to the location where your node.exe...
Read more >
Download & Update Node.js to the Latest Version! Node v19 ...
Direct download links to update to the latest Node.js versions: Node v19.0.0 / LTS v16.18.0.
Read more >
Update Node.js solution stack versions in Elastic Beanstalk
I receive an error when I try a manual or managed update to a newer version of a Node.js solution stack in AWS...
Read more >
Implement a stack using singly linked list - GeeksforGeeks
To implement a stack using the singly linked list concept, all the singly linked list operations should be performed based on Stack ......
Read more >
Npm install command failing with message "could not find ...
Npm install command failing with message "could not find Visual ... \node-gyp\lib\find-visualstudio.js:121:47) npm ERR! gyp ERR! stack at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found