Skip to content

fix: race condition when getting iOS inspector port #5544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/common/mobile/ios/simulator/ios-simulator-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
attachRequestMessage,
this.deviceInfo.identifier
);
const port = await super.getDebuggerPort(appId);

// Retry posting the notification every five seconds, in case the AttachRequest
// event handler wasn't registered when the first one was sent
const postNotificationRetryInterval = setInterval(() => {
this.$iOSEmulatorServices
.postDarwinNotification(
attachRequestMessage,
this.deviceInfo.identifier
)
.catch((e) => this.$logger.error(e));
}, 5e3);

// the internal retry-mechanism of getDebuggerPort will ensure the above
// interval has a chance to execute multiple times
const port = await super.getDebuggerPort(appId).finally(() => {
clearInterval(postNotificationRetryInterval);
});
try {
socket = await helpers.connectEventuallyUntilTimeout(async () => {
return this.$iOSEmulatorServices.connectToPort({ port });
Expand Down