Skip to content
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

fix: prevent user starting wails app twice #709

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rolznz
Copy link
Contributor

@rolznz rolznz commented Sep 25, 2024

Fixes #467

The simplest change to prevent Alby Hub running twice in Wails mode which could potentially cause corruption of the LDK directory. This is equivalent to how the http mode prevents it, but even better because the port is allocated even before the service starts.

@@ -20,6 +21,14 @@ var assets embed.FS
var appIcon []byte

func main() {
// Get a port lock on a rare port to prevent the app running twice
listener, err := net.Listen("tcp", "0.0.0.0:21420")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crazy. does this work across OS?
and it just listens but does not do anything? can we maybe write a pid-file like file to th working dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think writing a file is not so good because there is no guarantee it will be cleaned up. Trying to reserve a port seems safer to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a point. though most processes do write pid files for that case. I just have never seen an app reserving a port for this.
was wondering what are potential side effects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is a very creative approach, also wondered about side effects, but the fact that you don't run into lockfile problems is quite great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure Alby Hub Wails app cannot be run twice
3 participants