Sayed Yunus Nahid
Sayed Yunus Nahid

Reputation: 25

Could not acquire lock on uia2_device_port_guard. File already exists

I am new in Appium. I run my app from last 3 weeks by using this code. suddenly when I run this from another class it shows this error in appium server. I do know why it's occurring. I run it in the morning.

public class BaseClass {

public AndroidDriver<AndroidElement>  driver;

@BeforeClass
public  AndroidDriver<AndroidElement> capabilities() throws MalformedURLException{

    File appDir = new File("src/test/resources");
    File app = new File(appDir, "KandareeLiteApp.apk");
    
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    
    capabilities.setCapability("appPackage", "bd.com.cslsoft.kandareeliteapp");

    capabilities.setCapability("appActivity","bd.com.cslsoft.kandareeliteapp.view.activities.LauncherActivity");
    driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.resetApp();
}

Here is the Appium server-side code-- when start [Logcat] it take so much time.

     [W3C] Calling AppiumDriver.createSession() with args: [{"app":"D:\\Automation Project\\Resources\\KandareeLiteApp\\src\\test\\resources\\KandareeLiteApp.apk","appActivity":"bd.com.cslsoft.kandareeliteapp.view.activities.LauncherActivity","appPackage":"bd.com.cslsoft.kandareeliteapp","newCommandTimeout":"100","platformName":"Android","deviceName":"emulator-5554"},null,{"firstMatch":[{"appium:app":"D:\\Automation Project\\Resources\\KandareeLiteApp\\src\\test\\resources\\KandareeLiteApp.apk","appium:appActivity":"bd.com.cslsoft.kandareeliteapp.view.activities.LauncherActivity","appium:appPackage":"bd.com.cslsoft.kandareeliteapp","appium:deviceName":"emulator-5554","appium:newCommandTimeout":"100","platformName":"android"}]}]
     [BaseDriver] Event 'newSessionRequested' logged at 1606228007305 (20:26:47 GMT+0600 (Bangladesh Standard Time))
     [BaseDriver] Number capability passed in as string. Functionality may be compromised.
     [Appium] 
     [Appium] ======================================================================
     [Appium]   DEPRECATION WARNING:
     [Appium] 
     [Appium]   The 'automationName' capability was not provided in the desired 
     [Appium]   capabilities for this Android session
     [Appium] 
     [Appium]   Setting 'automationName=UiAutomator2' by default and using the 
     [Appium]   UiAutomator2 Driver
     [Appium] 
     [Appium]   The next major version of Appium (2.x) will **require** the 
     [Appium]   'automationName' capability to be set for all sessions on all 
     [Appium]   platforms
     [Appium] 
     [Appium]   In previous versions (Appium <= 1.13.x), the default was 
     [Appium]   'automationName=UiAutomator1'
     [Appium] 
     [Appium]   If you wish to use that automation instead of UiAutomator2, please 
     [Appium]   add 'automationName=UiAutomator1' to your desired capabilities
     [Appium] 
     [Appium]   For more information about drivers, please visit 
     [Appium]   http://appium.io/docs/en/about-appium/intro/ and explore the 
     [Appium]   'Drivers' menu
     [Appium] 
     [Appium] ======================================================================
     [Appium] 
     [Appium] Appium v1.18.3 creating new AndroidUiautomator2Driver (v1.56.1) session
     [Appium] Applying relaxed security to 'AndroidUiautomator2Driver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
     [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
     [BaseDriver] Creating session with W3C capabilities: {
     [BaseDriver]   "alwaysMatch": {
     [BaseDriver]     "platformName": "android",
     [BaseDriver]     "appium:app": "D:\\Automation          Project\\Resources\\KandareeLiteApp\\src\\test\\resources\\KandareeLiteApp.apk",
     [BaseDriver]     "appium:appActivity": "bd.com.cslsoft.kandareeliteapp.view.activities.LauncherActivity",
     [BaseDriver]     "appium:appPackage": "bd.com.cslsoft.kandareeliteapp",
     [BaseDriver]     "appium:deviceName": "emulator-5554",
     [BaseDriver]     "appium:newCommandTimeout": "100"
     [BaseDriver]   },
     [BaseDriver]   "firstMatch": [
     [BaseDriver]     {}
     [BaseDriver]   ]
     [BaseDriver] }
     [BaseDriver] Number capability passed in as string. Functionality may be compromised.
     [BaseDriver] Capability 'newCommandTimeout' changed from string ('100') to integer (100). This may cause unexpected behavior
     [BaseDriver] Session created with session id: 9ff2777d-7fcd-4a7e-8e9d-02b3eed680f0
     [BaseDriver] Using local app 'D:\Automation Project\Resources\KandareeLiteApp\src\test\resources\KandareeLiteApp.apk'
     [UiAutomator2] Checking whether app is actually present
     [ADB] Using 'adb.exe' from 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe'
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 start-server'
     [AndroidDriver] Retrieving device list
     [ADB] Trying to find a connected android device
     [ADB] Getting connected devices
     [ADB] Connected devices: [{"udid":"emulator-5554","state":"device"}]
     [AndroidDriver] Using device: emulator-5554
     [ADB] Using 'adb.exe' from 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe'
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 start-server'
     [ADB] Setting device id to emulator-5554
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
     [ADB] Current device property 'ro.build.version.sdk': 29
     [ADB] Getting device platform version
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
     [ADB] Current device property 'ro.build.version.release': 10
     [ADB] Device API level: 29
     [UiAutomator2] Relaxing hidden api policy
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell 'settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1''
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 wait-for-device'
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell echo ping'
     [AndroidDriver] Pushing settings apk to device...
     [ADB] Getting install status for io.appium.settings
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
     [ADB] 'io.appium.settings' is installed
     [ADB] Getting package info for 'io.appium.settings'
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
     [ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('3.2.0' >= '3.2.0')
     [ADB] There is no need to install/upgrade 'D:\New folder\Appium-windows-1.18.3\resources\app\node_modules\appium\node_modules\io.appium.settings\apks\settings_apk-debug.apk'
     [ADB] Getting IDs of all 'io.appium.settings' processes
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell 'pgrep --help; echo $?''
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell pgrep -f io\\.appium\\.settings'
     [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
     [Logcat] Starting logs capture with command:          C:\\Users\\syedyunus\\AppData\\Local\\Android\\Sdk\\platform-tools\\adb.exe -P 5037 -s emulator-5554 logcat -v threadtime
     [UiAutomator2] Deleting UiAutomator2 session
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop bd.com.cslsoft.kandareeliteapp'
     [Logcat] Stopping logcat capture
     [UiAutomator2] Restoring hidden api policy to the device default configuration
     [ADB] Running 'C:\Users\syedyunus\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy''
     [BaseDriver] Event 'newSessionStarted' logged at 1606228129127 (20:28:49 GMT+0600 (Bangladesh Standard Time))
     [W3C] Encountered internal error running command: Error: Could not acquire lock on C:\Users\SYEDYU~1\AppData\Local\Temp\uia2_device_port_guard. Original error: Error: EEXIST: file already exists, open 'C:\Users\SYEDYU~1\AppData\Local\Temp\uia2_device_port_guard'
     [W3C]     at guard (D:\New folder\Appium-windows-         1.18.3\resources\app\node_modules\appium\node_modules\appium-support\lib\util.js:477:13)
     [W3C] Destroying socket connection
     [HTTP] <-- POST /wd/hub/session 500 121825 ms - 1023

Upvotes: 2

Views: 756

Answers (4)

Sandeep
Sandeep

Reputation: 455

For Mac users:

  1. Open Terminal
  2. Go to /var/folders/92/hbvgxyp96p3f5vxzgsf1thh80000gp/T
  3. Delete file uia2_device_port_guard

Command:

rm uia2_device_port_guard

Upvotes: 0

Claudaette
Claudaette

Reputation: 41

Go to: C:\Users\(username)\AppData\Local\Temp\

Find: uia2_device_port_guard file

Delete it

Restart Appium server

Upvotes: 1

Irfan Khan
Irfan Khan

Reputation: 11

Please delete the uia2_device_port_guard file it will work normally. If you don't know the path then follow steps as below,

  1. Open run window(Ctrl+R)
  2. Type temp and click on OK
  3. Select all and clear all the temps files.
  4. Again write %temp% in open field and click on OK
  5. Select all and clear all the temps files
  6. uia2_device_port_guard file will delete automatically
  7. After deleting the both the temp files, refresh and reopen. It will work fine.

As i did exactly the same and it started working normally.

Upvotes: 0

Mamata Vibhute
Mamata Vibhute

Reputation: 11

You can Manually delete the file uia2_device_port_guard from given location, Then run. It worked for me as well.

Upvotes: 1

Related Questions