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

[BUG] desktop.el and org-roam-ui-mode: Cannot bind server socket: Address already in use #202

Open
serycjon opened this issue Jan 17, 2022 · 4 comments · May be fixed by #227
Open

[BUG] desktop.el and org-roam-ui-mode: Cannot bind server socket: Address already in use #202

serycjon opened this issue Jan 17, 2022 · 4 comments · May be fixed by #227
Assignees
Labels
bug Something isn't working

Comments

@serycjon
Copy link

Describe the bug
When using desktop.el to persist emacs state between sessions, the org-roam-ui-mode causes the loading of the persistent state fail. Each saved buffer has org-roam-ui-mode listed in its minor modes, causing the desktop.el to try to load org-roam-ui-mode for each of them. But all the calls to org-roam-ui-mode (except perhaps for the first one) result in error - "Cannot bind server socket: Address already in use".

To Reproduce

  1. have multiple buffers opened
  2. use org-roam-ui-mode
  3. quit emacs (saves the current session with desktop.el)
  4. start emacs (tries to load the previous session with desktop.el, but fails, because of repeated attempts to start org-roam-ui-mode server)

Additional context
Don't known if this is important, but I am using (setq desktop-restore-eager 10), making desktop.el restore 10 buffers immediately and restore the rest of them lazily.

Expected behavior
org-roam-ui-mode should fail gratiously (without elisp error, just with a message), when the server socket is already in use. Or maybe even better, it should detect that the socket is actually used by org-roam-ui-mode itself.

** Simple patch for my purposes **
I patched the org-roam-ui-mode to ignore errors. Proper solution would probably still need to let the user know about the issue.

(define-minor-mode
  org-roam-ui-mode
  "Enable org-roam-ui.
This serves the web-build and API over HTTP."
  :lighter " org-roam-ui"
  :global t
  :group 'org-roam-ui
  :init-value nil
  (cond
   (org-roam-ui-mode
   ;;; check if the default keywords actually exist on `orb-preformat-keywords'
   ;;; else add them
    (ignore-errors
      (setq-local httpd-port org-roam-ui-port)
      (setq httpd-root org-roam-ui-app-build-dir)
      (httpd-start)
      (setq org-roam-ui-ws-server
            (websocket-server
             35903
             :host 'local
             :on-open #'org-roam-ui--ws-on-open
             :on-message #'org-roam-ui--ws-on-message
             :on-close #'org-roam-ui--ws-on-close))
      (when org-roam-ui-open-on-start (org-roam-ui-open))))
   (t
    (progn
      (websocket-server-close org-roam-ui-ws-server)
      (httpd-stop)
      (remove-hook 'after-save-hook #'org-roam-ui--on-save)
      (org-roam-ui-follow-mode -1)))))
@serycjon serycjon added the bug Something isn't working label Jan 17, 2022
@serycjon
Copy link
Author

Probably even better patch is not to save org-roam-ui-mode and org-roam-ui-follow-mode in desktop.el:

  (add-to-list 'desktop-minor-mode-table
               '(org-roam-ui-mode nil))
  (add-to-list 'desktop-minor-mode-table
               '(org-roam-ui-follow-mode nil))

@chris-aeviator
Copy link

Org-roam-ui should make it easy to configure port & host (expose to your local network by binding to 0.0.0.0)

@serycjon
Copy link
Author

I don't think that is relevant to this issue. Even if I would set some different port, I believe that the issue is still the same - org-roam-ui tries to bind to that port multiple times, failing after the first try.

@cuttlefisch cuttlefisch linked a pull request Mar 24, 2022 that will close this issue
@tefkah tefkah linked a pull request Mar 25, 2022 that will close this issue
@Timmymayes
Copy link

I'm having this issue but also org-roam-ui is not following me despite follow mode being enabled. I disabled desktop saving and having the same issue, both the socket issue and the no-follow issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants