Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

'channel closed' on watch #287

Closed
prencher opened this issue Nov 30, 2016 · 15 comments
Closed

'channel closed' on watch #287

prencher opened this issue Nov 30, 2016 · 15 comments

Comments

@prencher
Copy link

Whenever webpack detects a change, the following happens:

Error: channel closed
    at ChildProcess.target.send (internal/child_process.js:540:16)
    at Object.send (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\checker\send.ts:24:35)
    at Checker.req (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\checker\checker.ts:87:21)
    at Checker.emitFile (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\checker\checker.ts:98:21)
    at transform (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\index.ts:106:29)
    at transformationFunction (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\index.ts:57:44)
    at compiler (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\index.ts:73:30)
    at Object.loader (C:\Projects\Aliso\node_modules\awesome-typescript-loader\src\index.ts:15:18)
    at LOADER_EXECUTION (C:\Projects\Aliso\node_modules\loader-runner\lib\LoaderRunner.js:114:14)
    at runSyncOrAsync (C:\Projects\Aliso\node_modules\loader-runner\lib\LoaderRunner.js:115:4)

This is with [email protected] with the simplest of configs:

const webpack = require('webpack');
const packageJson = require('./package.json');

module.exports = {
    entry: {
        app: './source/main.ts',
        vendor: Object.keys(packageJson['dependencies']),
    },
    output: {
        path: 'build',
        filename: '[name].js'
    },
    devtool: 'source-map',
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx'],
    },
    module: {
        loaders: [
            { test: /\.json$/, loader: 'json-loader' },
            { test: /\.tsx?$/, loader: 'awesome-typescript-loader' },
        ]
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js' })
    ],
};
@drywolf
Copy link

drywolf commented Nov 30, 2016

I'm experiencing the same problem when running webpack --watch with awesome-typescript-loader

at-loader version: 3.0.0-beta.9
webpack version: 2.1.0-beta.26

@FrozenPandaz
Copy link

I am also having this issue but only for a larger project.

@s-panferov
Copy link
Owner

s-panferov commented Dec 1, 2016

Hello everybody. It's very hard to debug things on Windows if you don't have one (webpack doesn't play well with virtualized environments), so I will appreciate any help with debugging.

And it also will be helpful to know more about your environments:

  1. OS version
  2. NodeJS version
  3. TypeScript version

@FrozenPandaz
Copy link

Sorry, here is my environment.

OS: Mac OS X El Capitan
Node: 6.9.1
Typescript: 2.1.1

@prencher
Copy link
Author

prencher commented Dec 2, 2016

Completely forgot to put that on the initial issue:

  • Windows 10
  • Node.js 6.9.1
  • TypeScript 2.0.10
  • Webpack 2.1.0-beta.27

@drywolf
Copy link

drywolf commented Dec 2, 2016

  • Windows 10
  • Nodejs 4.2.6
  • TypeScript 2.1.0-dev.20161011
  • Webpack 2.1.0-beta.26

@FrozenPandaz
Copy link

@s-panferov Has this info helped you reproduce the issue?

@zspecza
Copy link
Contributor

zspecza commented Dec 8, 2016

I'm also experiencing this problem on the latest Webpack 2 / TypeScript 2 releases (on macOS Sierra - Node 6.x)

I'm not too experienced with child process handling but I think the cause is either that the child process dies too soon or doesn't die at all... These are usually the causes of the "channel closed" error. I've tried playing with hooking on to SIGHUP / SIGTERM / etc signals in checker/checker.ts, checker/runtime.ts and checker/send.ts to try and close the child process with a graceful shutdown but haven't had any luck - I'm afraid the extent of my knowledge in this area isn't of much use here :(

For reference:

@s-panferov
Copy link
Owner

@FrozenPandaz neither I can reproduce the issue for all this time, nor my colleagues which use the loader.

I think I need to add some debug logging.

@s-panferov
Copy link
Owner

Just published a new version with more error handling. Please try 3.0.0-beta.10 and report errors if any.

@zspecza
Copy link
Contributor

zspecza commented Dec 9, 2016

@s-panferov Tried it with 3.0.0-beta.10, the stderr output is the same as before the update.

Error: channel closed
...

No other errors are being logged. ts-loader works, though.

It seems it has to do with webpack running multiple concurrent builds.

I put a reproducible case here: https://github.com/declandewet/awesome-ts-loader-bug

Just run npm run dev to start the webpack watcher, then change any .ts file in src/ to trigger an incremental build. You should see the channel closed error

@drywolf
Copy link

drywolf commented Dec 9, 2016

I can confirm that I am also getting the error only when I use multiple concurrent builds in webpack.config.js.
If I only export a single build config from webpack.config.js the problem does not occur.

@s-panferov
Copy link
Owner

@declandewet thanks for the example. I'll try to figure it out.

zspecza added a commit to zspecza/awesome-typescript-loader that referenced this issue Dec 10, 2016
zspecza added a commit to zspecza/awesome-typescript-loader that referenced this issue Dec 10, 2016
When exporting an array of configs from webpack.config.js, atl crashes.
The error message is "channel closed", indicating that a forked child
process is dying too soon. This commit changes the Channel class such
that it sends a SIGTERM to the child process rather than a SIGKILL.
The child process intercepts this signal and ignores it to ensure it is
kept alive.

Closes s-panferov#287
zspecza added a commit to zspecza/awesome-typescript-loader that referenced this issue Dec 10, 2016
When exporting an array of configs from webpack.config.js, atl crashes.
The error message is "channel closed", indicating that a forked child
process is dying too soon. This commit changes the Checker class such
that it's kill method sends a SIGTERM to the child process rather
than a SIGKILL. The child process intercepts this signal and
ignores it to ensure it is kept alive.

Closes s-panferov#287
@s-panferov
Copy link
Owner

s-panferov commented Dec 11, 2016

@declandewet thanks for the investigation.

I've found the main reason for that behavior. It's because atl fails to detect a --watch more in the latest webpack@beta and kills child processes after a first compilation.

I have several possibilities to fix this:

  1. Introduce a webpack plugin to reliably detect --watch mode
  2. Wait for an answer from here Detect --watch mode reliably  webpack/webpack#3460
  3. Don't rely on --watch mode detection, but this will require webpack to wait every time until TypeScript finishes its compilation to mark build as finished in --watch mode.

@s-panferov s-panferov mentioned this issue Dec 11, 2016
14 tasks
@Delagen
Copy link

Delagen commented Dec 12, 2016

#304

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants