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

Conversation

BenSjoberg
Copy link
Contributor

PR Checklist

What is the current behavior?

When running an iOS simulator app, the NativeScript CLI sends an AttachRequest notification to the application right after launch. If the runtime hasn't had time to set up the event handler for this notification yet, it's silently lost, and the CLI never gets the port number for debugging. This causes HMR to not work, and worse, the application auto-restarts after a minute. (The console shows the error "NativeScript debugger was not able to get inspector socket port")

This seems to be a race condition based on how quickly the iOS runtime sets up its event handler vs. how quickly the CLI sends the AttachRequest notification after launching the app. For some reason, I went from not experiencing this issue at all to experiencing it nearly 100% of the time when using the simulator on my Mac. (I haven't tested with an actual device. Also, I'm using the V8 iOS runtime.)

What is the new behavior?

I set up a timer to re-send the AttachRequest notification once every 5 seconds until getDebuggerPort() either returns or throws an error. In my testing, I was able to resolve it by adding a simple one-second delay before sending AttachRequest, but this seems more robust.

Fixes/Implements/Closes #3701. (Seems to be the same issue.)

@cla-bot cla-bot bot added the cla: yes label Jun 25, 2021
@BenSjoberg BenSjoberg changed the title Workaround for race condition when getting iOS debugging port fix(cli): race condition when getting iOS inspector port Jun 25, 2021
@NathanWalker
Copy link
Contributor

Thank you @BenSjoberg ! We'll include this with the upcoming 8.1 release.

@NathanWalker NathanWalker added this to the 8.1 milestone Jul 10, 2021
@rigor789 rigor789 changed the title fix(cli): race condition when getting iOS inspector port fix: race condition when getting iOS inspector port Jul 22, 2021
@rigor789 rigor789 merged commit 8f8dd83 into NativeScript:master Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants