Angular-cli: "Channel Closed" on ng serve rebuild with v1.5.0

Created on 3 Nov 2017  路  41Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

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

Versions.


```Angular CLI: 1.5.0
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.
<!--
Simple steps to reproduce this bug.
Please include: commands run, packages added, related code changes.
A link to a sample repo would help too.
-->

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.
<!-- Normally this include a stack trace and some more information. -->

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:\Datinode-ws\ng5-testnode_modules\@ngtools\webpack\src\angular_compiler_plugin.js:370:34)
at Promise.resolve.then (D:\Datinode-ws\ng5-testnode_modules\@ngtools\webpack\src\angular_compiler_plugin.js:208:22)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

webpack: Failed to compile.
```

Desired functionality.

Mention any other details that might be useful.

1 (urgent) broken bufix

Most helpful comment

Same issue here on win machine with medium large project. It works for some edits but then this error occurs. Sometimes immediately sometimes it takes some more rebuilds but it always end like this.

All 41 comments

Same here, after the second time I save a file.

Start command

ng serve --aot -H 0.0.0.0 --disable-host-check

Versions

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

@angular/cli: 1.5.0
@angular-devkit/core: 0.0.20
@ngtools/json-schema: 1.1.0
typescript: 2.4.2
webpack: 3.8.1

Error Message

webpack: Failed to compile.
webpack: Compiling...
Date: 2017-11-03T17:11:47.102Z
Hash: 00eb3265da52f37f4f00
Time: 3189ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry]
chunk {main} main.bundle.js (main) 520 kB [initial]
chunk {polyfills} polyfills.bundle.js (polyfills) 600 kB [initial]
chunk {styles} styles.bundle.js (styles) 811 kB [initial]
chunk {vendor} vendor.bundle.js (vendor) 15 MB [initial]

ERROR in Error [ERR_IPC_CHANNEL_CLOSED]: channel closed
    at ChildProcess.target.send (internal/child_process.js:557:16)
    at AngularCompilerPlugin._updateForkedTypeChecker (/workdir/p4-monitor-angular/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:370:34)
    at Promise.resolve.then (/workdir/p4-monitor-angular/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:208:22)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

webpack: Failed to compile.

Also seeing this exact behavior.

Same issue here on win machine with medium large project. It works for some edits but then this error occurs. Sometimes immediately sometimes it takes some more rebuilds but it always end like this.

Same problem !!

same problem. can't able to work

Update: on the same machine, switching to a fresh new node 8.9.0 64bit installation solved the issue for me!

Unfortunately I can't update to node 64bit, but did update from 8.1.3 to 9.0.0 (ARMv7) and still have that issue.

This issue happens when any changes made to the external file like interface or animation.

Same problem. I update Node a 8.9.1 - 32 bits and still have that problem.

I also have this problem,when the server rebuild ,throw error

image

problem solved by moving to node v9.1.

In v9.1. 32 bit. on second compile there comes no error however the server get stopped.
Any solution?

My solution was to downgrade back to cli v1.4

Thanks CramericalIndustries it worked 馃憤

I moved my project over to my laptop that had node version 6.11.3 and I stopped getting the errors. I also tried upgrading my version to 8.9.1 and 9.1, but I didn't have any luck getting it to work.

I think https://github.com/angular/angular-cli/pull/8306 might have solved this. Can you please try 1.6.0-beta.0 and tell me if you still get it?

@filipesilva is there a guide of how to install the beta releases? I tried doing npm i @angular/[email protected]. Then after the installation I executed ng -v and got lots of exceptions that told me that package xy is missing. After I've installed package xy it told me that now package xy1 is missing and so on. Maybe I should mention that I'm on a ARMv7.

gooood it's work after do this updats :

Angular CLI: 1.6.0-beta.0
Node: 8.9.1
OS: win32 ia32
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.0-beta.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
@schematics/angular: 0.1.2
typescript: 2.4.2
webpack: 3.8.1

still getting the same error with cli 1.6.0-beta.0, Ubuntu 16.04

ERROR in Error [ERR_IPC_CHANNEL_CLOSED]: channel closed
    at ChildProcess.target.send (internal/child_process.js:588:16)
    at AngularCompilerPlugin._updateForkedTypeChecker (/home/sand/Storage/sand/Local/WebstormProjects/Angular/smartscale-refactor/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:360:34)
    at Promise.resolve.then (/home/sand/Storage/sand/Local/WebstormProjects/Angular/smartscale-refactor/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.

ng -v 

Angular CLI: 1.6.0-beta.0
Node: 8.9.1
OS: linux x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

@angular/cdk: 5.0.0-rc0
@angular/cli: 1.6.0-beta.0
@angular/flex-layout: 2.0.0-beta.10-4905443
@angular/material: 5.0.0-rc0
@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.9.0-beta.0
@schematics/angular: 0.1.2
typescript: 2.6.1
webpack: 3.8.1

UPDATE: this error is not occurring in node 9.2 but there is another error I think it related to this issue:

<--- Last few GCs --->

[14909:0x3907ec0]  1660022 ms: Mark-sweep 1361.7 (1456.4) -> 1361.7 (1456.9) MB, 1192.7 / 0.0 ms  allocation failure GC in old space requested
[14909:0x3907ec0]  1661622 ms: Mark-sweep 1361.7 (1456.9) -> 1361.7 (1421.9) MB, 1599.5 / 0.0 ms  last resort GC in old space requested
[14909:0x3907ec0]  1662580 ms: Mark-sweep 1361.7 (1421.9) -> 1361.7 (1421.9) MB, 957.9 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3361a08a5749 <JSObject>
    1: getNodeLinks(aka getNodeLinks) [/home/sand/Storage/sand/Local/WebstormProjects/Angular/smartscale-refactor/node_modules/typescript/lib/typescript.js:~24230] [pc=0x159b3f222545](this=0x368bc03822d1 <undefined>,node=0x28448a91ab21 <SourceFileObject map = 0x2bd6b88ffe51>)
    2: checkSourceFileWorker(aka checkSourceFileWorker) [/home/sand/Storage/sand/Local/WebstormProjects/Angular/smartscal...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 2: 0x11e177c [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 6: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::NewInternal(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 7: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag, v8::internal::MinimumCapacity) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 8: 0xde7508 [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
 9: 0xde7752 [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
10: v8::internal::JSObject::NormalizeElements(v8::internal::Handle<v8::internal::JSObject>) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
11: 0xde83ce [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
12: v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
13: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
14: v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
15: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/home/sand/.nvm/versions/node/v9.2.0/bin/node]
16: 0x159b3e1842fd

image

what should i do to resove this issue?

I guess you should downgrade cli until they are fixed

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?

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 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.

My machine is Windows 10, node 8.9.1 64bits.

@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.

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

Do you have any locally linked folders / npm packages?

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

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.

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.

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!

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.

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

@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 I can confirm that the error is gone. Thank you very much. Also thanks to @bberto !

Same here. Fixed with 1.5.1. Thanks!

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.

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.

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._

Was this page helpful?
0 / 5 - 0 ratings