Skip to content
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

Fixed random test failure in Watchman watchers #113

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/watchman_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ function WatchmanClient(watchmanBinaryPath) {
this._backoffTimes = this._setupBackoffTimes();

this._clientListeners = null; // direct listeners from here to watchman.Client.

// Define a handler for if somehow the Node process gets interrupted. We need to
// close down the watchman.Client, if we have one.
process.on('SIGINT', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues:

  • This can leak memory. If a sane session using watchman is no longer being used, it will be retained by the process.on('SIGINT' handler until the process shutdown (or SIGINT) is worked
  • This wont handle other forms of shutdown, such as the process simply ending when it has no more work to do.

Ideas to resolve:

  • the global cleanup handler needs to be disabled via off during WatchmanWatcher.prototype.close
  • use capture-exit to handle all reasonable forms of exit + cooperation with other libraries attempting to do the same.

this._clearLocalVars();
});
}

// Define 'wildmatch' property, which must be available when we call the
Expand Down
2 changes: 1 addition & 1 deletion src/watchman_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ WatchmanWatcher.prototype.emitEvent = function(
*/

WatchmanWatcher.prototype.close = function(callback) {
this._client.closeWatcher();
this._client.closeWatcher(this);
callback && callback(null, true);
};

Expand Down