Xamarin-macios: Unable to claim server port 37265: Error binding to address: Address already in use

Created on 14 Feb 2019  路  6Comments  路  Source: xamarin/xamarin-macios

Steps to Reproduce

  1. Configure a simple Xamarin UI Test and run it on a physical device (iPhone SE in my case, connected to a MacMini)
  2. I get an "Unable to claim server port 37265" exception
  3. If the test is executed inside Visual Studio for Mac then it works perfectly

I already tried to killall iproxy before running the test but no process is found. Also running lsof -wni tcp:37265 indicates that the port is not in use before running the test

Expected Behavior

The test should run (it was running until few weeks ago)

Actual Behavior

Error: Unable to claim server port 37265: Error binding to address: Address already in use

Environment

=== Visual Studio Professional 2017 for Mac ===

Version 7.7.4 (build 1)
Installation UUID: f0ad42da-9dce-4e23-96e8-a95e4cbd19f9
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

    Package version: 516000221

=== Mono Framework MDK ===

Runtime:
    Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
    Package version: 516000221

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.8
    2.1.2
    2.1.1
    2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.504/Sdks
SDK Versions:
    2.1.504
    2.1.302
    2.1.301
    2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.15 (Visual Studio Professional)
Hash: d60abd198
Branch: 
Build date: 2019-02-01 12:23:30-0500

=== Xamarin.iOS ===

Version: 12.2.1.15 (Visual Studio Professional)
Hash: d60abd198
Branch: d15-9
Build date: 2019-02-01 12:23:29-0500

=== Xamarin.Android ===

Version: 9.1.8.0 (Visual Studio Professional)
Android SDK: /Users/ptmuser/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        8.0 (API level 26)
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 26.0.3

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/ptmuser/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.7.5.0
Hash: 06ceaea1

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 707040001
Git revision: 2a4679454f31c8bb887cfd181ea133c9149d3cad
Build date: 2019-01-30 16:18:21+00
Build branch: release-7.7.4
Xamarin extensions: c8b4305fd4c60b9c25947072eb150fdc3a5aa2b5

=== Operating System ===

Mac OS X 10.14.3
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Thu Dec 20 20:46:53 PST 2018
    root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Internet of Things (IoT) development (Preview) 7.5

Build Logs

SetUp Error : PTMate.UITest.Tests(iOS,"ba0dc7a28d6ee991bb4bed37d7347f47f426f84f|Real iPhone SE").Home_Tests
SetUp : System.Exception : Unable to start portforwarding: * Message: Probing for device(s)
*
Message: Device found: ba0dc7a28d6ee991bb4bed37d7347f47f426f84f

* (process:15634): CRITICAL *: Unable to claim server port 37265: Error binding to address: Address already in use
at Xamarin.UITest.iOS.iProxy.StartForward (System.String deviceIdentifier, System.Int32 hostPort, System.Int32 devicePort) [0x00091] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSAppLauncher.SetUpPortForwarding (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.iOS.Queries.DeviceInfo connectedDevice, System.Boolean useDeviceAgentPhysicalDevice) [0x0003e] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSAppLauncher.PrepareForDevice (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.iOS.Queries.DeviceInfo connectedDevice, System.Boolean useDeviceAgentPhysicalDevice, Xamarin.UITest.iOS.Instruments instruments) [0x00012] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchAppLocal (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, System.Boolean clearAppData) [0x00148] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchApp (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, Xamarin.UITest.TestCloud.TestCloudiOSAppConfiguration testCloudAppConfiguration, Xamarin.UITest.Shared.Http.HttpClient testCloudWsClient, Xamarin.UITest.Shared.Http.HttpClient xtcServicesClient, System.Boolean testCloudUseDeviceAgent) [0x00068] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSApp..ctor (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Execution.IExecutor executor) [0x002af] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.iOS.iOSApp..ctor (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration) [0x00000] in <2a16c16730a54859bda72c6bc1c728f7>:0
at Xamarin.UITest.Configuration.iOSAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <2a16c16730a54859bda72c6bc1c728f7>:0
at PTMate.UITest.IOSAppInitializer.StartApp (System.String deviceIdentifier) [0x0009f] in <678b85a18b1d42fd800dc320e23d0510>:0
at PTMate.UITest.Tests.BeforeEachTest () [0x00024] in <678b85a18b1d42fd800dc320e23d0510>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in <98fac219bd4e453693d76fda7bd96ab0>:0

iOS support

Most helpful comment

My solution was to kill iOS simulators before each fixture (which runs either on a simulator or a real device and almost all the time the simulators are running before the devices).
The simulator is keeping the port busy.

Therefore in my tests constructor I simply call:

var process = System.Diagnostics.Process.Start("killall", "Simulator");
process.WaitForExit();

All 6 comments

Even though you might only be hitting this issue locally, we research & triage Xamarin.UITest issues through the App Center support channels because there鈥檚 a lot of crossover between the testing platform and testing frameworks.

You can reach out to App Center support by logging into https://appcenter.ms/apps and clicking the chat icon in the lower right corner of the screen.
Here's a screenshot if you're having trouble finding the chat icon: https://www.screencast.com/t/uF8S5o0o0

Isn't it more useful to have discussion and triaging publicly available? I am now running into this exact issue and this is the only thing my Google-fu can find. Seems wasteful to have everyone contacting support.

I was able to fix this by doing the following:

  1. Disconnect iPhone
  2. Quit VPN software (Cisco AnyConnect)
  3. Reboot Mac
  4. Reboot iPhone
  5. Reconnect iPhone
  6. Try again

I suspect that the culprit was the VPN software (which has interfered with more things than I'd care to remember), but strangely enough simply quitting the VPN software and rebooting the iPhone was not enough. I apparently also needed to reboot the Mac? Anyway, hope this helps someone.

My solution was to kill iOS simulators before each fixture (which runs either on a simulator or a real device and almost all the time the simulators are running before the devices).
The simulator is keeping the port busy.

Therefore in my tests constructor I simply call:

var process = System.Diagnostics.Process.Start("killall", "Simulator");
process.WaitForExit();

Wow, maybe that's what it was for me as well then! I remember I had a simulator running before I rebooted, but not after I rebooted. That sounds like a bug that should be fixed.

@nathanielcook I had a very similar issue recently, however I targeted a simulator.
I didn't get an explicit message that the port could not be claimed, just that the POST failed.
However, diving in the folders ($TMPDIR/xdb/logs/[鈥) yielded precisely that port binding problem.
Although I couldn't see any running simulators, and always made sure to kill any of those before a test run, a reboot did indeed fix the problem.

Was this page helpful?
0 / 5 - 0 ratings