angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

"Channel Closed" on ng serve rebuild with v1.5.0

Open bberto opened this issue 9 years ago • 41 comments

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Node: 8.9.0
OS: win32 ia32
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

ng new ng5-test
cd ng5-test
ng serve

Then opened in Chrome. After editing a source file two times, I get the error below.

The log given by the failure.

chunk {inline} inline.bundle.js (inline) 5.79 kB [entry]
chunk {main} main.bundle.js (main) 20.3 kB [initial]
chunk {polyfills} polyfills.bundle.js (polyfills) 548 kB [initial]
chunk {styles} styles.bundle.js (styles) 33.5 kB [initial]
chunk {vendor} vendor.bundle.js (vendor) 7.02 MB [initial]

ERROR in Error [ERR_IPC_CHANNEL_CLOSED]: channel closed
    at ChildProcess.target.send (internal/child_process.js:588:16)
    at AngularCompilerPlugin._updateForkedTypeChecker (D:\Dati\node-ws\ng5-test\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:370:34)
    at Promise.resolve.then (D:\Dati\node-ws\ng5-test\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:208:22)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

webpack: Failed to compile.

Desired functionality.

Mention any other details that might be useful.

bberto avatar Nov 03 '17 15:11 bberto

image

what should i do to resove this issue?

farrukhazeem avatar Nov 16 '17 12:11 farrukhazeem

I guess you should downgrade cli until they are fixed

sandangel avatar Nov 16 '17 14:11 sandangel

Hi all, it looks like #8306 did not solve this problem.

Let me tell you a bit about what's happening. For rebuilds, we spawn a separate process that runs TypeScript type-checking separately. This speeds up rebuilds.

When you get a ERR_IPC_CHANNEL_CLOSED error that means that we tried to talk to the separate process and it wasn't there anymore (e.g. the process died/was killed). Right now this causes the compilation to fail.

I'm looking for solutions on how to address this. I don't think trying to respawn the process is the right solution, because it might just be dying over and over again on your system.

Instead I'm going to make compilation fallback to not using a separate process once the forked one dies. This will make rebuilds slower but at least you won't have to restart ng serve.

I'd still like to identify why the forked process dies. On my machine this doesn't happen. I don't think it happens on most projects since 1.5 has been out for a while but there haven't been that many reports. Things that affect most users get a lot more comments than in the first hours of breaking than this got in 24 days.

Has anyone seen a pattern to it? If you notice it happening only on some cases please let me know. https://github.com/angular/angular-cli/issues/8331#issuecomment-342874453 mentions that it happens only on interfaces/animations, did others see this pattern?

filipesilva avatar Nov 27 '17 12:11 filipesilva

With #8646 you will get a warning instead, and ng serve won't break. But rebuilds will be slower after that until you restart ng serve, since the forked type checker process is disabled.

filipesilva avatar Nov 27 '17 13:11 filipesilva

@filipesilva thank you. Did you try to reproduce the issue on your machine with node.js 32bit or 64bit? For me it looks like most people who do have that problem were using the 32bit node.js version.

CramericaIndustries avatar Nov 27 '17 13:11 CramericaIndustries

My machine is Windows 10, node 8.9.1 64bits.

filipesilva avatar Nov 27 '17 13:11 filipesilva

@filipesilva Thanks for your reply. I have not mention that this often happens on my machine when I use ng serve --aot --hmr with config described in angular-cli wiki. I think there are few people use hmr in their angular project so there are few reports at this time.

sandangel avatar Nov 27 '17 14:11 sandangel

I'm using ng serve -H 0.0.0.0 --disable-host-check and it crashed every 2nd time I've saved a file

CramericaIndustries avatar Nov 27 '17 14:11 CramericaIndustries

Do you have any locally linked folders / npm packages?

hansl avatar Nov 27 '17 18:11 hansl

Let's keep this open as we don't know the source of the error yet.

hansl avatar Nov 27 '17 18:11 hansl

If someone has time, you can try changing the code directly to see if an error is shown.

Open ./node_modules/@ngtools/webpack/src/type_checker.js and wrap the process.on('message', (message) => { body in a try catch:

process.on('message', (message) => {
    try {
      benchmark_1.time('TypeChecker.message');
      switch (message.kind) {
          // ...
      }
    benchmark_1.timeEnd('TypeChecker.message');
    } catch (e) {
      console.log(e);
    }
});

This way, next time it crashes, there should be an error logged. If you put the error here that might help us pinpoint the problem.

filipesilva avatar Nov 27 '17 18:11 filipesilva

I suspect that this issue may be related to the out of memory problems. I used to get it quite a lot together with Allocation failed - JavaScript heap out of memory in the main process. But I don't seem to get it after I increased memory limit. I'll keep observing and will post back if I face it again.

devoto13 avatar Nov 27 '17 18:11 devoto13

I tried to try/catch the code as requested by @filipesilva and discovered that the "message handler" is never invoked... then looking around for where the process is forked, I noticed this line on angular_compiler_plugin.js:354:

// Force max 8gb ram.
execArgv.push('--max-old-space-size=8192');

Sounded strange to me on 32bit architecture, so I commented it out. After that TypeChecker message handler is invoked and the issue disappeared!

bberto avatar Nov 27 '17 20:11 bberto

So, in my opinion, @filipesilva you were right: #8306 fix this issue. I didn't try 1.6.0-beta.0 because switching to node 64bit with 1.5.0 also worked for me.

bberto avatar Nov 27 '17 20:11 bberto

Wanted to test what @bberto suggested, commenting out the --max-old-space-size line in angular_compiler_plugin.js:354, so after a fresh install of angular (latest version; cli 1.5.4) in a Docker container (ARM), I've created a new project with ng new ng5-test and it turned out that there is no line with --max-old-space-size in the angular_compiler_plugin.js file. @bberto .../ng5-test/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js is that the correct file?

Now the good thing is that I've tried ng serve -H 0.0.0.0 --disable-host-check with that setup and it didn't crash even after the 10th time I've changed a file. So it looks like that it is working now.

I'll test it tomorrow with my real project and will report how it went.

Here is the ng -v output of my current setup (ARM 32bit):

Angular CLI: 1.5.4
Node: 8.1.3
OS: linux arm
Angular: 5.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.4
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.4
@schematics/angular: 0.1.7
typescript: 2.4.2
webpack: 3.8.1

CramericaIndustries avatar Nov 27 '17 21:11 CramericaIndustries

@bberto @CramericaIndustries the fix in #8306 was released in 1.5.1 so that line (execArgv.push('--max-old-space-size=8192');) shouldn't be there anymore.

@devoto13 now it uses the memory override of your main process (if any), so if your main process is running out of memory and you increase the limit, the child process will get the new limit as well.

filipesilva avatar Nov 27 '17 22:11 filipesilva

@filipesilva I can confirm that the error is gone. Thank you very much. Also thanks to @bberto !

CramericaIndustries avatar Nov 28 '17 11:11 CramericaIndustries

Same here. Fixed with 1.5.1. Thanks!

bberto avatar Nov 28 '17 18:11 bberto

I've found a memory leak in the forked type checker. This only occurs when using --aot, and causes the forked type checker to increase in memory over time.

The issue is opened in https://github.com/angular/angular/issues/20691 and awaiting resolution.

filipesilva avatar Nov 29 '17 15:11 filipesilva

The combination of https://github.com/angular/angular-cli/pull/8306, https://github.com/angular/angular-cli/pull/8646 (released in CLI 1.5.5) and https://github.com/angular/angular/pull/20692 (to be released in Angular 5.0.4) should address all the problems found here.

If you still have problems when using CLI 1.5.5 with Angular 5.0.4 please let me know so we can reopen and investigate further.

filipesilva avatar Nov 30 '17 09:11 filipesilva