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

ng build output truncated when run as a child process #10922

Closed
imhoffd opened this issue May 18, 2018 · 7 comments
Closed

ng build output truncated when run as a child process #10922

imhoffd opened this issue May 18, 2018 · 7 comments
Labels
area: etc/misc needs: more info Reporter must clarify the issue
Milestone

Comments

@imhoffd
Copy link
Contributor

imhoffd commented May 18, 2018

The output of ng build is truncated to 8192 bytes when run as a child process.

Versions

Angular CLI: 6.0.1
Node: 8.10.0
OS: darwin x64
Angular: 6.0.2
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@angular/cli                      6.0.1
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.1
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

  • git clone https://github.com/dwieeb/ng-build-truncated-output
  • npm install
  • node script.js

Observed behavior

image

Desired behavior


screen shot 2018-05-18 at 2 57 40 pm

Mention any other details that might be useful (optional)

Something I observed is that using setBlocking(true) in the ng bin file appears to flush the output properly:

#!/usr/bin/env node
'use strict';

process.stdout._handle.setBlocking(true);
process.stderr._handle.setBlocking(true);

// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
process.title = 'ng';

var version = process.version.substr(1).split('.');
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
  process.stderr.write(
    'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
    'The official Node.js version that is supported is 8.9 and greater.\n\n' +
    'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
  );

  process.exit(3);
}

require('../lib/init');

Could be related to stdout not being flushed before a process.exit() is called.

@filipesilva
Copy link
Contributor

This is an interesting problem. For reference the issues on node seem to be nodejs/node#2360 and nodejs/node#19218.

A specially relevant highlight is nodejs/node#19218 (comment):

And the root cause identified as the fact that console.log non blocking, so if a process issues it and exits afterwards, the actual number of bytes written depends on the time gap between the two actions and the capability of the I/O channel to transfer the data in between the gap.

This makes me think that we shouldn't use console.log across our loggers and use process.stdout.write instead.

imhoffd added a commit to ionic-team/ionic-cli that referenced this issue Jun 4, 2018
Without this, the 'error' event is unhandled, which results in the
process dying. Print the error and move on.

Added because of 'write after end' stream error from shelling out
Angular CLI. Possibly revert pending this issue: angular/angular-cli#10922
@imhoffd
Copy link
Contributor Author

imhoffd commented Nov 14, 2018

@filipesilva Would you accept a PR where the loggers are switched to using process.stdout.write?

@filipesilva
Copy link
Contributor

filipesilva commented Nov 15, 2018

@dwieeb I think we already do now in CLI 7.

Our webpack build uses a provided logger:

export const getBrowserLoggingCb = (verbose: boolean): LoggingCallback =>
(stats, config, logger) => {
// config.stats contains our own stats settings, added during buildWebpackConfig().
const json = stats.toJson(config.stats);
if (verbose) {
logger.info(stats.toString(config.stats));
} else {
logger.info(statsToString(json, config.stats));
}
if (stats.hasWarnings()) {
logger.warn(statsWarningsToString(json, config.stats));
}
if (stats.hasErrors()) {
logger.error(statsErrorsToString(json, config.stats));
}
};

The logger is instantiated in the CLI:

const logger = createConsoleLogger();

And will use process.stdout and process.stderr:

export function createConsoleLogger(
verbose = false,
stdout: ProcessOutput = process.stdout,
stderr: ProcessOutput = process.stderr,
): logging.Logger {

@imhoffd
Copy link
Contributor Author

imhoffd commented Nov 16, 2018

Interesting, I'm still seeing this with latest CLI.

Angular CLI: 7.0.6
Node: 10.12.0
OS: darwin x64
Angular: 7.0.4
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.6
@angular-devkit/build-angular     0.10.6
@angular-devkit/build-optimizer   0.10.6
@angular-devkit/build-webpack     0.10.6
@angular-devkit/core              7.0.6
@angular-devkit/schematics        7.0.6
@angular/cli                      7.0.6
@ngtools/webpack                  7.0.6
@schematics/angular               7.0.6
@schematics/update                0.10.6
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.19.1

The following trick still works:

process.stdout._handle.setBlocking(true);
process.stderr._handle.setBlocking(true);

I can investigate further next week.

@ngbot ngbot bot added this to the needsTriage milestone Jan 24, 2019
@alan-agius4
Copy link
Collaborator

Hi @dwieeb, is this still a problem?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label May 25, 2020
@imhoffd
Copy link
Contributor Author

imhoffd commented May 26, 2020

No, I haven't seen this in a while.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: etc/misc needs: more info Reporter must clarify the issue
Projects
None yet
Development

No branches or pull requests

3 participants