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

isAlive false, no error in electron, but isAlive true (same IP) under node? #134

Closed
JamesNewton opened this issue Dec 31, 2020 · 6 comments

Comments

@JamesNewton
Copy link

I'm baffled. Any insight on how to debug this appreciated. We are using ping to check if a robot is online before we attempt to connect to it. The specific code is:
https://github.com/cfry/dde/blob/master/core/robot.js#L1049

copied here for your convenience: (and THIS code IS open source, so I can share it)

                let ping = require('ping') //https://www.npmjs.com/package/ping
                ping.sys.probe(this.ip_address,
                                function(isAlive, err){
                                    if (isAlive) {
                                        if(job_instance.name == "set_link_lengths") { //don't attempt to set link lengths again!
                                            this_robot.start_aux(job_instance)
                                        }
                                        else { setTimeout(function(){
                                                            this_robot.set_link_lengths(this_job)
                                                          },
                                                          500)} //in case dexster is booting up, give it a chance to complete boot cycle
                                        //this_robot.use_ping_proxy(job_instance)
                                    }
                                    else if (err){
                                        this_job.stop_for_reason("errored_from_dexter_connect", "Ping on robot: " + this_robot.name + " errored with: " + err.message)
                                    }
                                    else {
                                        this_job.stop_for_reason("errored_from_dexter_connect", "Could not connect to Dexter.\nIf it is because Dexter is initializing,\ntry again in a minute,\nor click Misc pane 'simulate' button.", true)
                                        //3rd arg is true so that we will run the stop method for dex_read_file job,
                                        //so that this error of "not connected" will reset the orig editor files menu item.
                                    }
                                },
                               {timeout: 10}
                               )

On Windows, and Mac, this code is working (e.g. reaching the "if (isAlive)" clause when the robot is online and pingable. In Ubuntu 16 and 18, it is reaching the "else {" clause, not the "else if (err) {" clause.

At the same time, on the same Ubuntu 18 machine, a ping to the same IP address from bash is returned, and the following little node.js test code works as expected, reporting "Dex is alive" every time:

let ping = require('ping') //https://www.npmjs.com/package/ping
ping.sys.probe("192.168.0.142"
        , function(isAlive, err){
                var msg = isAlive ? 'Dex is alive' : 'Dex is dead:'+err;
                console.log(msg);
                }
        , {timeout: 10}
        );

I have searched the electron issues for any mention of ping not working. e.g.
https://github.com/electron/electron/issues?q=is%3Aissue+%22node-ping%22+
and I'm not finding anything.

I've also, of course, searched your issues for anything related to electron and none of that seems to match:
https://github.com/danielzzz/node-ping/issues?q=is%3Aissue+electron

I'm sort of at a point of... I don't know how to go forward here. It's probably an electron issue, but I was hoping you might have some ideas.

@JamesNewton
Copy link
Author

To narrow this down, I use the source code of node-ping to write code that does the same thing, in a very minimal version inside the electron app. "out" is just console log, but it goes to a special text box which is easy to see while the program is running.

var cp = require('child_process');
ping = cp.spawn("ping", ["192.168.0.142"]);
ping.stdout.on('data', (data) => {
  out(`stdout: ${data}`);
});

ping.stderr.on('data', (data) => {
  out(`stderr: ${data}`);
});

ping.on('close', (code) => {
  out(`child process exited with code ${code}`);
});

the stderr message comes back as stderr: ping: icmp open socket: Operation not permitted
and the child process existed with code 2.

Why doesn't node-ping report an error? Maybe I wrote the minimal code incorrectly? But the same code runs just fine under node, so electron is failing to run it with the same permissions...

@JamesNewton
Copy link
Author

Wonder if it's related to this:
electron/electron#18521

@JamesNewton
Copy link
Author

Submitted a bug report to Electron.
electron/electron#27168

@mondwan
Copy link
Collaborator

mondwan commented Apr 7, 2021

Try 0.4.1, and see whether the error stderr: ping: icmp open socket: Operation not permitted can be reported now

@JamesNewton
Copy link
Author

Sorry, it's been 4 months so we moved on and are no longer using this library at all. Rather than pretend that I could find time to revert, update the library and try it, I will just let you know that testing won't happen. Close this issue if you feel you've corrected the problem.

@mondwan
Copy link
Collaborator

mondwan commented Apr 8, 2021

oops. Anyway, thanks for the report.

@mondwan mondwan closed this as completed Apr 8, 2021
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

No branches or pull requests

2 participants