server not stopping before restart when editing Gruntfile.js #22

Closed
pensierinmusica opened this Issue Oct 13, 2013 · 6 comments

Comments

Projects
None yet
3 participants
@pensierinmusica

Hi,

I have Grunt "watch" looking at some files and restarting Express if they get changed.

It all works seamlessly. For some weird reason though if the file edited is Gruntfile.js, grunt-express-server doesn't stop Express before relaunching when the express:dev task is triggered by grunt-watch and obviously it generates an EADDRINUSE error.

This is my grunt-watch configuration:

    watch: {
      options: {
        livereload: true
      },
      stylus: {
        files: ['<%= yeoman.app %>/styles/sections/*.styl'],
        tasks: ['stylus'],
        options: {livereload: false}
      },
      autoprefixer: {
        files: ['<%= yeoman.app %>/styles/*.css'],
        tasks: ['autoprefixer']
      },
      express: {
        files: [
          'app.js',
          'config/*.js',
          'controllers/*.js',
          'models/*.js',
          'Gruntfile.js'
        ],
        tasks: ['express:dev'],
        options: {spawn: false} // Without this option specified express won't be reloaded
      }

And this is my grunt-express-server configuration:

    express: {
      options: {
        port: process.env.PORT || 3000
      },
      dev: {
        options: {
          script: 'app.js'
        }
      },
      prod: {
        options: {
          script: 'app.js',
          node_env: 'production'
        }
      }
    }

The weird thing is that the problem ony happens with Gruntfile.js. If I modify, let's say, app.js or one of the controllers, the task correctly stops Express before reloading it.

Any thoughts?? Thanks!

@ericclemmons

This comment has been minimized.

Show comment
Hide comment
@ericclemmons

ericclemmons Oct 18, 2013

Owner

I'm not really sure yet, but I have to ask, why restart the server if the Gruntfile changes?

Owner

ericclemmons commented Oct 18, 2013

I'm not really sure yet, but I have to ask, why restart the server if the Gruntfile changes?

@pensierinmusica

This comment has been minimized.

Show comment
Hide comment
@pensierinmusica

pensierinmusica Oct 21, 2013

I guess you're right... I could just live-reload the browser :)

I guess you're right... I could just live-reload the browser :)

@jalcine

This comment has been minimized.

Show comment
Hide comment
@jalcine

jalcine Nov 15, 2013

I'm having this issue when I'm editing my package.json and wanting to reload the server to include new packages like middleware and the likes.

jalcine commented Nov 15, 2013

I'm having this issue when I'm editing my package.json and wanting to reload the server to include new packages like middleware and the likes.

@ericclemmons

This comment has been minimized.

Show comment
Hide comment
@ericclemmons

ericclemmons Dec 1, 2013

Owner

Wow, that's really odd! I was able to reproduce it, & trying to figure out why Gruntfile.js changes would cause this!

Owner

ericclemmons commented Dec 1, 2013

Wow, that's really odd! I was able to reproduce it, & trying to figure out why Gruntfile.js changes would cause this!

@ericclemmons

This comment has been minimized.

Show comment
Hide comment
@ericclemmons

ericclemmons Dec 1, 2013

Owner

Apparently Gruntfile.js is auto-watched, which doesn't properly emit the proper signals to kill the server. As a result, the next iteration of watch seems to run the task in a new namespace, meaning the server never shuts down.

Trying an alternative now...

Owner

ericclemmons commented Dec 1, 2013

Apparently Gruntfile.js is auto-watched, which doesn't properly emit the proper signals to kill the server. As a result, the next iteration of watch seems to run the task in a new namespace, meaning the server never shuts down.

Trying an alternative now...

@ericclemmons

This comment has been minimized.

Show comment
Hide comment
@ericclemmons

ericclemmons Dec 1, 2013

Owner

Aha! Stupid Grunt being clever. I'm having to introduce process._servers to keep the server in memory for stopping, since Grunt explicitly clears the require cache.

Owner

ericclemmons commented Dec 1, 2013

Aha! Stupid Grunt being clever. I'm having to introduce process._servers to keep the server in memory for stopping, since Grunt explicitly clears the require cache.

@ghost ghost assigned ericclemmons Dec 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment