question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running an app in debug should not fail due to other apps running packager

See original GitHub issue

Describe the Feature

Running new app should work no matter if there has been other apps running (with packager) - ideally they would not collide.

Currently if you have an app already running in debug, it has it’s packager running (by default in port 8081). When you try to run a second app, it will not spawn a launcher due to finding 8081 part having a packager already running. This will try to run the second app in the first apps packager, which will fail with an error:

rn_metro

This is unnecessary friction and requires manually killing the terminal each time you are switching to dev another application (or define the port yourself).

Possible Implementations

I did a twitter poll to see the expectations, here are the results

image

This confirmed my own feeling: Best option would be not to mess with the already running app. Instead, we would find a new port to run it.

I did some experimentations and based on those here is my proposed solution:

  1. If --port is used and is not the default (8081) try to use the specified port. If it is in use, we don’t launch packager - you are manually requesting the port and we don’t want to change it
  2. If default port, we check for running processes listening in TCP range 8081-8089 (for example)
  3. We check if any of those is packager instance for the app we want to run (for example, slight modification for /status that stores also the project root). If yes, we don’t launch a new packager, but use the existing one
  4. Find first free port in the range (again, 8081-8089 for example) and launch packager there

This would replace the current logic:

  1. If defined port (default 8081) is in use and it’s status is running, don’t do anything
  2. Otherwise try launching a new packager in the port - fail if not able to

POC

I have a POC for iOS locally very close to working, but I wanted to make sure this would be something that is wanted before going forward and finishing it. Android side of implementation is pending still as well.

Changes required so far:

  • Slight modification for cli-server-api statusMiddleWare (/status), so it returns JSON with running status and projectRoot (so we can later check if the running packager is for the current project or not)
  • Start packager bin/sh script changes to do steps 1-4 listed in the proposed solution

Any comments on the proposed solution? Some reasons why it wouldn’t work or not wanted to have in the first place? Any changes requested / required? Good to go? If all is good, I’ll keep working on this and make a PR out of it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thymikeecommented, Dec 7, 2022

Asked internally if someone finds some time to help on this. Let’s see how it goes 😃

1reaction
plrdevcommented, Dec 6, 2022

@plrdev are you still interested in this feature? I’m gonna reopen, because it’s clearly beneficial to have this

Hey thanks for the reminder on this. I’d be willing to work on this but I think I’d like to check this together with someone with the experience on the repo/codebase. Anyone willing to give some guidance and discuss this further?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found