Skip to content

Fixed: There is an exception when stopping livesync --watch #1996

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

Merged
merged 1 commit into from
Aug 12, 2016

Conversation

tzraikov
Copy link
Contributor

  1. create a new {N} project.
  2. start tns livesync ios --watch.
  3. make a change.
  4. try to stop tns process with Ctrl+C. You will see ugly exception.

@KristinaKoeva
Copy link
Contributor

Will you share what the ugly exception is

@tzraikov
Copy link
Contributor Author

^CTypeError: Cannot convert undefined or null to object
at LiveSyncService.Gaze.close (/Users/raikov/work/nativescript-cli/node_modules/gaze/lib/gaze.js:151:10)
at (/Users/raikov/work/nativescript-cli/lib/common/services/process-service.ts:26:21)
at arrayEach (/Users/raikov/work/nativescript-cli/node_modules/lodash/lodash.js:451:11)
at Function.forEach (/Users/raikov/work/nativescript-cli/node_modules/lodash/lodash.js:8634:14)
at ProcessService.executeAllCallbacks (/Users/raikov/work/nativescript-cli/lib/common/services/process-service.ts:25:4)
at process. (/Users/raikov/work/nativescript-cli/lib/common/services/process-service.ts:12:53)
at emitNone (events.js:86:13)
at process.emit (events.js:185:7)
at Signal.wrap.onsignal (internal/process.js:199:44)
/Users/raikov/work/nativescript-cli/node_modules/gaze/lib/gaze.js:151
Object.keys(self._watchers).forEach(function (file) {
^

TypeError: Cannot convert undefined or null to object
at LiveSyncService.Gaze.close (/Users/raikov/work/nativescript-cli/node_modules/gaze/lib/gaze.js:151:10)
at /Users/raikov/work/nativescript-cli/lib/common/services/process-service.js:25:31
at arrayEach (/Users/raikov/work/nativescript-cli/node_modules/lodash/lodash.js:451:11)
at Function.forEach (/Users/raikov/work/nativescript-cli/node_modules/lodash/lodash.js:8634:14)
at ProcessService.executeAllCallbacks (/Users/raikov/work/nativescript-cli/lib/common/services/process-service.js:24:11)
at process. (/Users/raikov/work/nativescript-cli/lib/common/services/process-service.js:7:79)
at emitOne (events.js:101:20)
at process.emit (events.js:188:7)
at process.exit (internal/process.js:146:15)
at process. (/Users/raikov/work/nativescript-cli/lib/common/errors.js:65:13)
at emitOne (events.js:96:13)
at process.emit (events.js:188:7)
at process._fatalException (bootstrap_node.js:254:26)

@KristinaKoeva
Copy link
Contributor

I spent some time debugging this issue and I came to a conclusion that the ugly exception is caused because the process exit handler is executed 2 times. This happens because when you press Ctrl+C the process sends two signals and the handler is executed once for each signal. The first execution stops the gaze watcher, but the second one tries to stop it again which results in that exception. I would suggest you do something like

this.$processService.attachToProcessExitSignals(this, () => {
    if (gazeWatcher) {
        gazeWatcher.close();
        gazeWatcher = null;
    }
});

@tzraikov
Copy link
Contributor Author

Well, another round of digging and the issue seems to be a bit simpler. Calling gazeWatcher.close without a closure destroys its context. So the close method can't do its job.

@tzraikov tzraikov force-pushed the raikov/fix-livesync-watch branch from 53caba0 to a001dec Compare August 12, 2016 05:46
@enchev
Copy link
Contributor

enchev commented Aug 12, 2016

👍

@KristinaKoeva
Copy link
Contributor

Even better 👍

@tzraikov tzraikov merged commit 3afa813 into master Aug 12, 2016
@tzraikov tzraikov deleted the raikov/fix-livesync-watch branch August 12, 2016 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants