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
Zombie ngrok processes #58
Comments
I think I understand the scenario as it's being described, I'm not quite sure I understand the harm it's causing. Zombie processes aren't real processes, they're defunct and shouldn't consume any resources and should be harmless, and I don't think there's a good way for Regarding the |
By the way, the test here (and the one below it) test for when an external command terminates our |
That's why I mentioned it's more of just an OS housekeeping issue than a functional problem. I just happen to have an application that could end up with hundreds of zombie processes before the parent app gets restarted. I doubt I'll run out of process IDs though, which I believe would be the only danger. I don't think pyngrok is affecting the stability of ngrok itself. ngrok is what it is, and I've accepted to just live with it and work around it as it is worth the benefits it provides. The ngrok process seems to hang randomly from hours to days so I don't think it's related to a TTL setting. Just for some background on how I noticed this, I used to just try and do a I'll look at the test code when I get a chance and see if there is anything that can be done. |
Also fwiw, the code I currently have is working very well aside from the zombie processes accumulating. Here is the class method I use to stop the tunnels before starting them up again (I have 2 tunnels: http and ssh), it also addresses issue 53:
On a side note, I started passing in the config to every pyngrok call to keep the log chatter down with |
Yah, a few weeks after released that new feature, I wished I'd make Thanks for sharing the context. I'll close this ticket for now, but it's always helpful to have these threads for others to find if they experience similar issues! |
I think because of this ngrok process issue, it kept turning back on when new processes were automatically started, so I just passed it in at every call. |
Oh that’s a good point. A global default wouldn’t be a bad idea. |
Hey, just doing some poking around on this today. Seems like we should be able to reproduce this in a until test using I can test further on a Linux machine at another time, but in the meantime, I wonder if this is the culprit here. Unsure if you have the code cloned locally, but if you made the change to use Additionally, adding If you have the means to try that and either give you an luck, let me know and I can work on a more official solution! |
Just can't let it go huh? 😁 I'll try some of those suggestions to see if it changes the behavior, and get back to you. |
🤷🏻♂️ Interesting as Ice Age: Dawn of the Dinosaurs is, I needed something else to occupy my brain whilst watching it with the little one. |
I'm still working on getting my test environment fully set up , but I ran the process test suite and test_start_process_port_in_use actually results in a zombie ngrok process until the thread terminates. I haven't dug into the exact cause yet though. None of the other tests have that issue. |
Interesting. This leads me to suspect you're correct that a zombie process is the result of |
Adding
|
Awesome! Feel free to throw it in a PR if it works, I can cut a release later today if all looks good. |
I think that fixes my original issue. It might ultimately depend on exactly how the ngrok process dies in production to determine for sure though, and that I'll have to test over the next few days by letting it run. I'll put together a PR in the meantime. |
Adding some tests, then will cut a release this evening. But have a look at the changelog, also added the |
This has been resolved and merged. |
Not sure if this is a pyngrok issue or not, but it's something I'm running into and wanted to bring it to your attention. Feel free to close if it's a Python or ngrok binary issue, or if it's too much of a niche problem. It's more of just an OS housekeeping issue than a functional problem.
Describe the Bug
I have a long running application that always keeps an ngrok tunnel open using pyngrok. The tunnel occasionally drops and my application will automatically start a new one. Sometimes the ngrok process itself fails to respond, so the process is killed and then relaunched automatically with the next connect(). Over time, zombie ngrok processes accumulate (on linux) and remain in the process tree until the Python application (the parent process) is terminated or restarted.
Steps to Reproduce
I run a timer thread to check for connection every few minutes and restart the tunnel when necessary, but it can probably also be simulated with a loop and delay.
ngrok.connect()
kill ngrok process externally with linux kill statement (simulating a crash of the ngrok binary)
ngrok.disconnect(
) will result in a ngrok.exception.PyngrokNgrokURLErrorngrok.get_tunnels()
will result in a ngrok.exception.PyngrokNgrokURLErrorngrok.kill()
leaves defunct zombie processngrok.connect()
starts new ngrok processRestarting the Python program clears out all of the zombie ngrok processes (as it should).
Expected Behavior
Defunct ngrok processes should be removed by the calling process (Python?) at the time the child process exits.
Environment
Additional Context
I'm not sure why the ngrok process randomly stops responding, but it happens at least every few days.
Also, this is running on a Raspberry Pi
The text was updated successfully, but these errors were encountered: