Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs do not flush before Java exit #3009

Closed
1 of 5 tasks
ZachBien opened this issue Sep 30, 2021 · 4 comments · Fixed by #3028
Closed
1 of 5 tasks

Logs do not flush before Java exit #3009

ZachBien opened this issue Sep 30, 2021 · 4 comments · Fixed by #3028
Labels
bug This issue is a bug. language/java Related to Java bindings module/runtime Issues affecting the `jsii-runtime` p1

Comments

@ZachBien
Copy link

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

General Information

  • JSII Version: 1.33.0 (build 7951e32), typescript 3.9.10
  • Platform: Darwin Kernel Version 18.7.0

What is the problem?

console.log("Log lines") are not guaranteed to be written when executed in the Java export. It appears that the logs are not flushed in JavaScript before the Java program exits. Sleeping/Debugging at the end of the the Java program allows the JavaScript logs to be written.

Jsii TS code:

export class MockSleeper implements ISleeper {
    sleep(timeMillis: number): void {
        console.log(`Mocked implementation! Not performing real sleep of ${timeMillis}`);
    }
}

Java code:

public static void main(String[] args) {
    MockSleeper m = new MockSleeper();
    m.sleep(39);
    System.out.println("debug here");
}

I will only see the output from the TS log (Mocked impl...) if I debug the Java program at the last line.

@ZachBien ZachBien added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2021
@RomainMuller RomainMuller added language/java Related to Java bindings module/runtime Issues affecting the `jsii-runtime` p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2021
@RomainMuller
Copy link
Contributor

@all-contributors add @ZachBien for bug

@allcontributors
Copy link
Contributor

@RomainMuller

I've put up a pull request to add @ZachBien! 🎉

@RomainMuller
Copy link
Contributor

Okay I was able to reproduce this on JDK8 (Amazon Corretto 8), but not with Amazon Corretto 17.

It does look like this might be caused by how the JVM handles the subprocess...

RomainMuller added a commit that referenced this issue Oct 5, 2021
In some cases, messages sent by JavaScript using `console.log` and
similar may not be completely flushed by the time the Java thread that
forwards that data is closed. This is because the thread might not have
been given a chance to run when `this.stop` is set to true, which makes
it exit immediately.

This change adds a new step that triggers once `this.stop` becomes
`true` that will flush the `inputStream` until EOF in a blocking way.
When this happens, the child process has already been requested to exit,
and so EOF should be reached relatively quickly.

Fixes #3009
@mergify mergify bot closed this as completed in #3028 Oct 11, 2021
mergify bot pushed a commit that referenced this issue Oct 11, 2021
In some cases, messages sent by JavaScript using `console.log` and
similar may not be completely flushed by the time the Java thread that
forwards that data is closed. This is because the thread might not have
been given a chance to run when `this.stop` is set to true, which makes
it exit immediately.

This change adds a new step that triggers once `this.stop` becomes
`true` that will flush the `inputStream` until EOF in a blocking way.
When this happens, the child process has already been requested to exit,
and so EOF should be reached relatively quickly.

Fixes #3009



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. language/java Related to Java bindings module/runtime Issues affecting the `jsii-runtime` p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants