Skip to content

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

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

Closed
bberto opened this issue Nov 3, 2017 · 41 comments
Closed

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

bberto opened this issue Nov 3, 2017 · 41 comments
Assignees
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken type: bug/fix

Comments

@bberto
Copy link

bberto commented Nov 3, 2017

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.

@CramericaIndustries
Copy link

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.

@vultix
Copy link

vultix commented Nov 3, 2017

Also seeing this exact behavior.

@BenjaminDobler
Copy link

BenjaminDobler commented Nov 3, 2017

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.

@bellib
Copy link

bellib commented Nov 4, 2017

Same problem !!

@sheikalthaf
Copy link
Contributor

same problem. can't able to work

@bberto
Copy link
Author

bberto commented Nov 7, 2017

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

@CramericaIndustries
Copy link

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.

@pervizsalmanov
Copy link

pervizsalmanov commented Nov 8, 2017

Also, I use: https://yadi.sk/d/PISF7IxL3PX6w2

@sheikalthaf
Copy link
Contributor

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

@vallinplasencia87
Copy link

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

@hpyou
Copy link

hpyou commented Nov 9, 2017

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

image

@seelfidha
Copy link

seelfidha commented Nov 9, 2017

problem solved by moving to node v9.1.

@ShubhamRungta
Copy link

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

@CramericaIndustries
Copy link

CramericaIndustries commented Nov 9, 2017

My solution was to downgrade back to cli v1.4

@ShubhamRungta
Copy link

Thanks CramericalIndustries it worked 👍

@Eric-Larson
Copy link

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.

@Brocco Brocco added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken labels Nov 10, 2017
@filipesilva
Copy link
Contributor

I think #8306 might have solved this. Can you please try 1.6.0-beta.0 and tell me if you still get it?

@CramericaIndustries
Copy link

CramericaIndustries commented Nov 12, 2017

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

@bellib
Copy link

bellib commented Nov 14, 2017

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

@sandangel
Copy link

sandangel commented Nov 15, 2017

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

@farrukhazeem
Copy link

image

what should i do to resove this issue?

@sandangel
Copy link

I guess you should downgrade cli until they are fixed

@filipesilva
Copy link
Contributor

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. #8331 (comment) mentions that it happens only on interfaces/animations, did others see this pattern?

filipesilva added a commit to filipesilva/angular-cli that referenced this issue Nov 27, 2017
This PR will prevent the main thread for exiting when the forked type checker exists unexpectedly.

A warning will be logged on the console when this happens:

```
WARNING in AngularCompilerPlugin: Forked Type Checker exited unexpectedly. Falling back to typechecking on main thread.
```

Fix angular#8331
@filipesilva
Copy link
Contributor

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.

@CramericaIndustries
Copy link

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

@filipesilva
Copy link
Contributor

My machine is Windows 10, node 8.9.1 64bits.

@sandangel
Copy link

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

@CramericaIndustries
Copy link

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

@hansl
Copy link
Contributor

hansl commented Nov 27, 2017

Do you have any locally linked folders / npm packages?

@hansl
Copy link
Contributor

hansl commented Nov 27, 2017

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

@filipesilva
Copy link
Contributor

filipesilva commented Nov 27, 2017

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.

@devoto13
Copy link
Contributor

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.

@bberto
Copy link
Author

bberto commented Nov 27, 2017

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
Copy link
Author

bberto commented Nov 27, 2017

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.

@CramericaIndustries
Copy link

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

@filipesilva
Copy link
Contributor

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

@CramericaIndustries
Copy link

CramericaIndustries commented Nov 28, 2017

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

@bberto
Copy link
Author

bberto commented Nov 28, 2017

Same here. Fixed with 1.5.1. Thanks!

@filipesilva
Copy link
Contributor

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 angular/angular#20691 and awaiting resolution.

filipesilva added a commit that referenced this issue Nov 29, 2017
This PR will prevent the main thread for exiting when the forked type checker exists unexpectedly.

A warning will be logged on the console when this happens:

```
WARNING in AngularCompilerPlugin: Forked Type Checker exited unexpectedly. Falling back to typechecking on main thread.
```

Fix #8331
filipesilva added a commit that referenced this issue Nov 29, 2017
This PR will prevent the main thread for exiting when the forked type checker exists unexpectedly.

A warning will be logged on the console when this happens:

```
WARNING in AngularCompilerPlugin: Forked Type Checker exited unexpectedly. Falling back to typechecking on main thread.
```

Fix #8331
@filipesilva
Copy link
Contributor

The combination of #8306, #8646 (released in CLI 1.5.5) and angular/angular#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.

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
This PR will prevent the main thread for exiting when the forked type checker exists unexpectedly.

A warning will be logged on the console when this happens:

```
WARNING in AngularCompilerPlugin: Forked Type Checker exited unexpectedly. Falling back to typechecking on main thread.
```

Fix angular#8331
@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 Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests