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

feat(dotnet,java): kernel process inherits host's STDERR #2248

Merged
merged 16 commits into from
Jan 7, 2021

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 12, 2020

Removed the code that surrounded handling of the STDERR stream from
the Kernel process: there is no need to PIPE it, and simply inheriting
it (i.e: subprocess STDERR is the same stream as the parent's) results
in a more intuitive behavior, as STDERR output from child processes
surfaces "immediately" even if the parent process somehow cannot
forward it anymore (e.g: if it crashed or deadlocked). This also means
the STDERR forwarding thread is no longer needed.


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

Removed the code that surrounded handling of the `STDERR` stream from
the Kernel process: there is no need to PIPE it, and simply inheriting
it (i.e: subprocess STDERR is the same stream as the parent's) results
in a more intuitive behavior, as STDERR output from child processes
surfaces "immediately" even if the parent process somehow cannot
forward it anymore (e.g: if it crashed or deadlocked). This also means
the STDERR forwarding thread is no longer needed.
@RomainMuller RomainMuller added language/dotnet Related to .NET bindings (C#, F#, ...) language/java Related to Java bindings effort/small Small work item – less than a day of effort module/runtime Issues affecting the `jsii-runtime` contribution/core This is a PR that came from AWS. labels Nov 12, 2020
@RomainMuller RomainMuller requested a review from a team November 12, 2020 16:38
@RomainMuller RomainMuller self-assigned this Nov 12, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I understand: the child process respects JSII_DEBUG and will only output traces to stderr in that case. So it's safe to just INHERIT stderr, correct?

@@ -38,8 +38,7 @@ public NodeProcess(IJsiiRuntimeProvider jsiiRuntimeProvider, ILoggerFactory logg
StandardInputEncoding = utf8,
RedirectStandardOutput = true,
StandardOutputEncoding = utf8,
RedirectStandardError = true,
StandardErrorEncoding = utf8
UseShellExecute = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good change but usually has implications on being able to locate executables. Have you tested this on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • According to .NET's own documentation, UseShellExecute = false is required if you set any Redirect* to true.
  • The default value of this property is false on .NET Core (but true on .NET Framework). This is only making it explicit

void IDisposable.Dispose()
{
StandardInput.Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these not needed anymore ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardInput, StandardOutput and StandardError are actually directly obtained from properties of the Process instance... When we call Dispose() on the process, it naturally disposes of all resources it owns, including those streams.

Additionally, Dispose() might abruptly terminate the stream, possibly without having flushed some buffered data. Calling Close() instead tends to ensure the buffer is flushed out before the close happens, so the node process gets the signal we are trying to send.

@@ -10,19 +9,14 @@ internal sealed class Runtime : IRuntime
public Runtime(INodeProcess nodeProcess)
{
_nodeProcess = nodeProcess ?? throw new ArgumentNullException(nameof(nodeProcess));
if (Environment.GetEnvironmentVariable("JSII_DEBUG") != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What functionality do we lose here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, STDERR from anywhere in node (i.e: console.error from user's apps) were only surfaced to the console of non-JS applications when JSII_DEBUG was set to true. This means the behavior of a program was different if you ran it "pure JavaScript" versus through a jsii binding. Hence I think this was actually a bug and not a feature.

@mergify
Copy link
Contributor

mergify bot commented Jan 7, 2021

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Jan 7, 2021
@mergify
Copy link
Contributor

mergify bot commented Jan 7, 2021

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-5lHf64IXfvmr
  • Commit ID: a624312
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 70ce153 into main Jan 7, 2021
@mergify mergify bot deleted the rmuller/stderr-inherit branch January 7, 2021 11:26
@mergify
Copy link
Contributor

mergify bot commented Jan 7, 2021

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort language/dotnet Related to .NET bindings (C#, F#, ...) language/java Related to Java bindings module/runtime Issues affecting the `jsii-runtime`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants