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

Ionic Server doesn’t shutdown gracefully using Cordova #3036

Closed
bubbsi opened this issue Mar 26, 2018 · 10 comments
Closed

Ionic Server doesn’t shutdown gracefully using Cordova #3036

bubbsi opened this issue Mar 26, 2018 · 10 comments
Labels
Milestone

Comments

@bubbsi
Copy link

bubbsi commented Mar 26, 2018

Description:
I have to build an ionic cordova app. So I prepared my macOS with all needed utilities. First I have to create the app on the browser platform. Therefore I start the process with “ionic cordova run browser”. After testing I just want to shutdown the server with crtl+c, but even a node process will be left. So every time I would have to kill the process using the command line tool “kill”. It isn’t really comfortable.

I found out if I run only the command “cordova run browser” without an ionic build the server is shutting down correctly. The same thing, if I run “ionic serve” without using cordova

My ionic info:

cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:
cordova (Cordova CLI) : 8.0.0

local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : browser 5.0.3
Ionic Framework : ionic-angular 3.9.2

System:
ios-deploy : 1.9.1
Node : v8.10.0
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b

Environment Variables:
ANDROID_HOME : not set

Misc:
backend : legacy
@imhoffd
Copy link
Contributor

imhoffd commented Mar 26, 2018

Related: #3022

@bubbsi Can you run pgrep -lf ionic and show the output?

@marxide
Copy link

marxide commented Mar 26, 2018

I also have this issue. When I use ionic cordova run browser, it builds my project and starts a node server on port 8000. When I kill the server with Ctrl+C, the node server doesn't stop. I have to stop it manually with kill.

$ ionic cordova run browser
Running app-scripts build: --platform browser --target cordova

... (build output)

> cordova run browser
startPage = index.html
Static file server running @ http://localhost:8000/index.html
CTRL + C to shut down

...

$ pgrep -lf ionic
1621 ionic MACHINE_OS=x86_64_Darwin
1622 ionic MACHINE_OS=x86_64_Darwin TERM_PROGRAM=iTerm.app

$ ps aux | grep node
andrew            1641   0.0  0.4  3184728  61048 s000  S+    9:38am   0:01.29 node /path/to/project/node_modules/.bin/cordova run browser

$ lsof -i :8000
COMMAND  PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    1641 andrew   11u  IPv6 0x5460f93470ec8a15      0t0  TCP *:irdmi (LISTEN)

After terminating with Ctrl+C

$ pgrep -lf ionic
1622 ionic MACHINE_OS=x86_64_Darwin TERM_PROGRAM=iTerm.app

$ ps aux | grep node
andrew            1641   0.0  0.4  3185240  65572 s000  S     9:38am   0:01.72 node /path/to/project/node_modules/.bin/cordova run browser

$ lsof -i :8000
COMMAND  PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    1641 andrew   11u  IPv6 0x5460f93470ec8a15      0t0  TCP *:irdmi (LISTEN)

Ionic info

$ ionic info

cli packages: (/path/to/env/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 7.0.0 browser 5.0.3
    Ionic Framework    : ionic-angular 3.9.2

System:

    ios-deploy : 1.9.0
    ios-sim    : 5.0.8
    Node       : v8.10.0
    npm        : 5.6.0
    OS         : macOS Sierra
    Xcode      : Xcode 9.1 Build version 9B55

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

@imhoffd
Copy link
Contributor

imhoffd commented Mar 26, 2018

@bubbsi @marxide The Ionic CLI doesn't officially support the Cordova browser platform. See my reasoning here: #2312 (comment)

I'm most interested in if this is happening for ionic serve, which the original issue says it is.

@marxide
Copy link

marxide commented Mar 26, 2018

@dwieeb Fair enough. I can confirm this doesn't happen to me when using ionic serve, everything seems to shutdown properly.

Sidenote: I'm only using the browser platform because I want to test my app as I write, but when I use ionic serve it doesn't load any of the Cordova plugins (e.g. Native Storage). From what I've gathered, this is expected. Is there another way I can test my app as I develop? Spinning up a device emulator or attaching a real device each time feels slow and inconvenient. Am I missing something?

@bubbsi
Copy link
Author

bubbsi commented Mar 27, 2018

Same Issue, it is really hard to code, if you can‘t test it while writing. The most other ways and workarounds need to much time.

@imhoffd
Copy link
Contributor

imhoffd commented Mar 27, 2018

@marxide @bubbsi I think using the Cordova browser platform as a testing platform is a good use case, as long as the dev understands it shouldn't be used for production. The decision has to be made early during app development, right? If the dev ever plans to target the desktop, the usage of Cordova plugins needs to be coded defensively with platform detection.

Basically,

doNativeThing() {
  if (this.platform.is('cordova')) {
    // use cordova plugin
  } else {
    // use web api
  }
}

But, if the dev plans to never target the desktop, the Cordova browser platform can be used as a testing framework. The code would just be:

doNativeThing() {
  // use cordova plugin
}

This has always been an annoyance that comes hand-in-hand with having a single code base being able to target multiple platforms 😄 It's an annoyance we're trying to solve with Capacitor.

Having understood your use case, I will investigate why there are leftover processes using ionic cordova run browser. Thanks!

@imhoffd imhoffd added the bug label Mar 27, 2018
@imhoffd imhoffd added this to the CLI Future milestone Mar 27, 2018
@imhoffd
Copy link
Contributor

imhoffd commented Mar 27, 2018

@marxide @bubbsi Thinking this over a bit more, I may want to rework how the Cordova browser platform is used in the Ionic CLI. In an app with the Cordova integration enabled, instead of running ionic cordova run browser, one would run ionic serve, and the Ionic CLI would prepare everything Cordova needs. This would mean instead of doing a build and then cordova run, which is slow and doesn't have livereload, we'd use the livereload dev server from ionic serve and pull in all the Cordova files that the browser platform needs to run.

To me, ionic cordova run browser takes too long each time and isn't very useful while developing. I can make this work much better, but it'll be a little while before I start working on this, unfortunately.

@imhoffd
Copy link
Contributor

imhoffd commented Mar 27, 2018

👉 #3043

@marxide
Copy link

marxide commented Mar 28, 2018

Thanks @dwieeb, that is exactly what I'm looking for. I have no intention of deploying a browser target (yet) so I was only using the browser platform to get around the Cordova plugin issue. I would much prefer to use ionic serve as you describe.

I look forward to trying it out when available.

@imhoffd
Copy link
Contributor

imhoffd commented Jul 30, 2018

Closing in favor of #3043, please subscribe to it for updates.

@imhoffd imhoffd closed this as completed Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants