@@ -705,17 +705,6 @@ class DevicePlugin extends BasePlugin {
705705 const device = await getDevice ( {
706706 session_id : sessionId ,
707707 } ) ;
708- await unblockDeviceMatchingFilter ( { session_id : sessionId } ) ;
709- log . info ( `📱 Unblocking the device that is blocked for session ${ sessionId } ` ) ;
710- const res = await next ( ) ;
711- await EventBus . fire ( new AfterSessionDeletedEvent ( { sessionId : sessionId , device : device } ) ) ;
712- if ( device ?. platform === 'ios' && device . realDevice ) {
713- try {
714- await DEVICE_CONNECTIONS_FACTORY . releaseConnection ( device . udid , device . mjpegServerPort ) ;
715- } catch ( err ) {
716- log . warn ( `Error while releasing connection for device ${ device . udid } . Error: ${ err } ` ) ;
717- }
718- }
719708
720709 // Collect all ports used by the device and release them
721710 const portsToRelease : ( number | undefined | null ) [ ] = [ ] ;
@@ -729,6 +718,7 @@ class DevicePlugin extends BasePlugin {
729718
730719 // Android ports (stored on device if available)
731720 if ( device . systemPort ) portsToRelease . push ( device . systemPort ) ;
721+ if ( device . adbPort ) portsToRelease . push ( device . adbPort ) ;
732722
733723 // Ports from sessionResponse capabilities (Android and iOS)
734724 // sessionResponse contains the capabilities returned from Appium
@@ -759,6 +749,18 @@ class DevicePlugin extends BasePlugin {
759749 }
760750 }
761751
752+ await unblockDeviceMatchingFilter ( { session_id : sessionId } ) ;
753+ log . info ( `📱 Unblocking the device that is blocked for session ${ sessionId } ` ) ;
754+ const res = await next ( ) ;
755+ await EventBus . fire ( new AfterSessionDeletedEvent ( { sessionId : sessionId , device : device } ) ) ;
756+ if ( device ?. platform === 'ios' && device . realDevice ) {
757+ try {
758+ await DEVICE_CONNECTIONS_FACTORY . releaseConnection ( device . udid , device . mjpegServerPort ) ;
759+ } catch ( err ) {
760+ log . warn ( `Error while releasing connection for device ${ device . udid } . Error: ${ err } ` ) ;
761+ }
762+ }
763+
762764 // Release all collected ports
763765 const validPorts = portsToRelease . filter ( ( p ) => p !== null && p !== undefined ) ;
764766 if ( validPorts . length > 0 ) {
0 commit comments