Bug 39981 - [XVS 4.0] Unending "Trying to connect..." message with no other diagnostic information if the PATH environment variable is cleared via the .bashrc file on the Mac
Summary: [XVS 4.0] Unending "Trying to connect..." message with no other diagnostic in...
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 4.0.0 (C6)
Hardware: PC Windows
: --- normal
Target Milestone: 4.2.0 (C8)
Assignee: Brendan Zagaeski (Xamarin Team, assistant)
Depends on:
Reported: 2016-03-29 22:03 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-07-08 11:57 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Verbose IDE logs (2.10 KB, application/zip)
2016-03-29 22:03 UTC, Brendan Zagaeski (Xamarin Team, assistant)

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-03-29 22:03:35 UTC
Created attachment 15550 [details]
Verbose IDE logs

[XVS 4.0] Unending "Trying to connect..." message with no other diagnostic information if the PATH environment is cleared via the .bashrc file on the Mac

This is in some ways a follow-up to Bug 36642. The fix for Bug 36642 altered the way _errors_ in the `.bashrc` file were treated by the connection process. This bug discusses another way the `.bashrc` file can interfere with the connection process.

## Possible improvements

### Part A: Perhaps exclude the `.bashrc` file from being loaded at all during `Ssh.Connect()`?

Based on some quick tests I tried, it seems that the "SSH.NET" library itself is loading the `.bashrc` file during the `SshClient.Connect()` method. So I'm not sure if it will be easy to change this behavior. Even if it is easy, there are some potential arguments in favor of _keeping_ the `.bashrc` file. For example some advanced users might use their `.bashrc` file to configure particular settings that they also _want_ to apply to the build host connection. On the other hand, I'm not familiar with any common scenarios where this would be helpful, so perhaps it would indeed be sensible to exclude the `.bashrc` file from the load process for now if possible. That would reduce the number of factors involved in the connection process.

### Part B: Fail quickly

The connection never aborts during the steps to replicate as described below. I would expect the connection to fail as soon as Visual Studio tries to run a command that cannot be found on the Mac.

### Part C: Improve the log messages

The steps to replicate as described below currently produce _no_ diagnostic messages. I would expect the Output window and the log files to display some messages to indicate which particular steps or commands failed during the connection process.


## Steps to replicate

1. If you have previously connected to the Mac build host, use the context menu in the VS connection dialog to forget the Mac.

2. Create a file at "$HOME/.bashrc" on the Mac build host that contains the following line:


3. Attempt to pair Visual Studio to the Mac build host. The connection dialog will display "Trying to connect..."

4. Wait a few minutes. The dialog will not show any progress or change.

5. Cancel the connection. The connection dialog and the toolbar icon will still indicate that VS is attempting to connect to the build host.

## Results

(I ran these tests with verbose logging enabled via `devenv /log`.)

### Connection dialog

The connection dialog shows "Trying to connect..." indefinitely.

### Output window 

No messages.

### `*Ide.log` file from "Help > Xamarin > Zip Logs"

There are no messages that indicate a problem. The last message in the log file is the beginning of the connection attempt:

>  MacServer State transition from DisconnectedState to SshConnectingState on MacBuildHost.local (

## Version info (brief)

Windows 10 (64-bit)
XamarinVS (a78562a)

OS X 10.11
(The Xamarin versions on the Mac do not affect this behavior.)
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-29 22:04:04 UTC
## Behavior of other SSH clients

Just for additional context and background information, here are some notes about how other SSH clients behave in this scenario.

### BAD: OpenSSH one-liners

If you try a one-liner to run a command via `ssh` in a Git Bash command prompt (from Git for Windows [1]), the `.bashrc` file _will_ be read and you _will_ see a problem:

> $ ssh macuser@ "ls"
> Password:
> bash: ls: No such file or directory

[1] https://git-for-windows.github.io/

### BAD: SSH.NET `SshClient.RunCommand()` 

As with OpenSSH, if you run a command using `SshClient.RunCommand()` from the SSH.NET library, the `.bashrc` file _will_ be read and you _will_ see a problem.

### "GOOD": OpenSSH interactive session

One different result that could some confusion is that an _interactive_ `ssh` session in a Git Bash command prompt does _not_ load the `.bashrc` file, so you will _not_ see a problem:

> $ ssh macuser@ "ls"
> MacBuildHost:~ macuser$ ls
> Desktop                 Downloads               Movies                  Pictures
> Documents               Library                 Music                   Public
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-29 23:52:36 UTC
## Correction for the steps to replicate from Comment 0

To get the exact behavior described in this bug report, you must already have SSH key files stored on the Windows side. So before step 1, be sure to pair once _successfully_ with the Mac build host.

(If you do _not_ have stored key files, the connection process will fail quickly, and you will get errors in the log files indicating that `ssh-keygen` failed to execute. Accordingly, the more interesting scenario for possible improvements B and C (from Comment 0) is when there _are_ stored key files because then the connection process does _not_ fail quickly or provide error messages.)
Comment 3 mag@xamarin.com 2016-05-10 17:50:25 UTC
Fixed in master branch. Merge commit: 77293dae7aec74164c54896d14d4a10c82ea001a
Comment 4 Saurabh 2016-07-08 11:57:10 UTC
I can also reproduce this Issue with XVS (a78562a) and getting same like: 

### Connection dialog
The connection dialog shows "Trying to connect..." indefinitely.

screencast: http://www.screencast.com/t/uBR18ZYtT

Environment info from VS:
VS log:

I have also checked this issue with latest master build XVS and observed that VS connect to mac build host successfully after adding a file at "$HOME/.bashrc" on the Mac build host that contains the following line:
"Foo" and PATH=""

Supplement Info:
Screencast: http://www.screencast.com/t/MLiVXvtNgV

Environment info: https://gist.github.com/Sadik1/b13f4099493b7832e6bf16429f974985
Xamarin Log: https://gist.github.com/Sadik1/e9123c0f0fd045131fb02d6d039ed717