Skip to content

Commit 8f8dd83

Browse files
BenSjobergrigor789
andauthored
fix: race condition when getting iOS inspector port (#5544)
* fix(cli): race condition when getting iOS inspector port fixes #3701 * Update lib/common/mobile/ios/simulator/ios-simulator-device.ts Co-authored-by: Igor Randjelovic <[email protected]>
1 parent 517e082 commit 8f8dd83

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/common/mobile/ios/simulator/ios-simulator-device.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,23 @@ export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
8787
attachRequestMessage,
8888
this.deviceInfo.identifier
8989
);
90-
const port = await super.getDebuggerPort(appId);
90+
91+
// Retry posting the notification every five seconds, in case the AttachRequest
92+
// event handler wasn't registered when the first one was sent
93+
const postNotificationRetryInterval = setInterval(() => {
94+
this.$iOSEmulatorServices
95+
.postDarwinNotification(
96+
attachRequestMessage,
97+
this.deviceInfo.identifier
98+
)
99+
.catch((e) => this.$logger.error(e));
100+
}, 5e3);
101+
102+
// the internal retry-mechanism of getDebuggerPort will ensure the above
103+
// interval has a chance to execute multiple times
104+
const port = await super.getDebuggerPort(appId).finally(() => {
105+
clearInterval(postNotificationRetryInterval);
106+
});
91107
try {
92108
socket = await helpers.connectEventuallyUntilTimeout(async () => {
93109
return this.$iOSEmulatorServices.connectToPort({ port });

0 commit comments

Comments
 (0)