winapps
winapps copied to clipboard
App start fails with BAD_PORT message because grep returns multiple IPs
For reasons that are unclear to me, ip neigh returns two IPs with the MAC of my VM's only interface. As a result, the grep commands used to get the IP return a variable containing two IPs, separated by a newline. obviously this mangles the command of the netcat check, and feeding bash $IP $PORT || waThrowExit is going to always throw an exit, if not the right one.
More correct behavior would be to throw a (new to the codebase) BAD_IP error, or to iterate over the IPs, since the port value is actually fine.
My short term fix is to add -m1 to the grep command that matches on the VM's MAC. Of course, if the first IP is the bad one, this will not work.
I also suggest adding on ip '${RDP_IP}' immediately after the port in the BAD_PORT error notification in any case, because doing that is what led to me understanding the problem.
I realize the cause of this issue is not internal to the project, but it is a case of not catching bad input
The only thing I did that might have caused this is a force reset of my VM because it was hung. everything worked before i did that.
@fitzmorrispr I agree that iterating over multiple returned IP addresses is a reasonable approach, along with improving the error message to include the IP address for easier debugging. Out of curiosity, were the two returned IP addresses on the same subnet?
Even if the issue resulted from a forced VM reset, the WinApps script should be made resilient enough to handle unexpected input. A possible improvement could be issuing a warning for each failed IP attempt while only raising an error after all potential addresses have been tried.
If you have the time, feel free to open a PR with your proposed fixes. Thanks!