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

Handle multiple Obsidian instances to avoid socket conflicts when using multiple vaults #2

Open
mathe00 opened this issue Sep 29, 2024 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@mathe00
Copy link
Owner

mathe00 commented Sep 29, 2024

When multiple instances of Obsidian are opened simultaneously (e.g., when working with multiple vaults), socket conflicts can occur, potentially leading to unexpected behavior.

Problem:

  • Each instance of the plugin may attempt to use the same socket, resulting in conflicts or crashes.
  • There is no mechanism to ensure that each instance gets a unique socket to communicate properly.

Proposed Solutions:

  1. Port Scanning for Available Sockets:

    • Upon launching a new instance, the plugin could scan for available ports in a defined range. If the default socket is in use, it could dynamically bind to the next available port.
    • This ensures that each instance operates on a different port without conflicts.
  2. Instance ID and Socket Assignment:

    • Each vault instance could be assigned a unique ID, and the plugin would append this ID to the socket name.
    • This method avoids port collisions and simplifies instance identification.
  3. Centralized Socket Management:

    • Implement a centralized socket manager that runs on the first instance of Obsidian. Other instances would communicate through this central manager to avoid direct socket conflicts.
    • This would allow all instances to share the same communication channel without direct socket handling.
  4. User Notification and Recovery:

    • If a socket conflict is detected, show a notification to the user, allowing them to choose whether to retry with a different port or abort the operation.
    • This improves user experience by providing transparency and control over the situation.

Additional Considerations:

  • Ensure that any solution is cross-platform compatible and works seamlessly on Windows, macOS, and Linux.
  • The solution should not degrade performance or cause delays when launching multiple vaults.
  • If necessary, provide advanced configuration options for users to define custom ports or handle multiple instances manually.

This feature would greatly improve the user experience when managing multiple Obsidian instances, particularly for those who work with multiple vaults simultaneously.

@mathe00 mathe00 self-assigned this Sep 29, 2024
@mathe00 mathe00 added the bug Something isn't working label Sep 29, 2024
@mathe00
Copy link
Owner Author

mathe00 commented Sep 30, 2024

Hey everyone,

I’ve been struggling with this issue for a while (disclaimer: I'm not a JS developer 😅) and I’ve been trying to get it done with ChatGPT’s help. I’ve almost got it working, but the code ended up messy and unorganized. So I figured it would be better to let an experienced dev handle it properly.

What I need:

  • Automatically generate a unique random ID if no socket file name is provided.
  • Append this ID to the socket file name.
  • Ensure the socket path is properly constructed and updated when Obsidian restarts (no need for dynamic updates during runtime).

If anyone could help implement this cleanly into the code, that would be fantastic! I’ve almost got there, but it’s pretty cracra now and not production-ready.

Thanks in advance!

@mathe00 mathe00 added the help wanted Extra attention is needed label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant