Skip to content

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

Merged
tzraikov merged 1 commit into
masterfrom
raikov/fix-livesync-watch
Aug 12, 2016
Merged

tzraikov merged 1 commit into
masterfrom
raikov/fix-livesync-watch

Conversation

@tzraikov

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Will you share what the ugly exception is

@tzraikov

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

enchev commented Aug 12, 2016

Copy link
Copy Markdown
Contributor

👍

@KristinaKoeva

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