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

Crashes on FreeBSD with "Mutex.lock: Resource deadlock avoided" #245

Closed
ALPHA-60 opened this issue Sep 3, 2020 · 8 comments
Closed

Crashes on FreeBSD with "Mutex.lock: Resource deadlock avoided" #245

ALPHA-60 opened this issue Sep 3, 2020 · 8 comments

Comments

@ALPHA-60
Copy link

ALPHA-60 commented Sep 3, 2020

When compiled on FreeBSD 12.1 with ocamlc 4.09.1 from opam, running lsp server results in:

ocamllsp: internal error, uncaught exception:
          Sys_error("Mutex.lock: Resource deadlock avoided")
          Raised by primitive operation at file "lsp/src/scheduler.ml", line 108, characters 4-22
          Called from file "lsp/src/scheduler.ml", line 272, characters 4-22
          Called from file "lsp/src/rpc.ml", line 17, characters 14-39
          Called from file "ocaml-lsp-server/src/ocaml_lsp_server.ml", line 750, characters 4-39
          Called from file "lsp/src/logger.ml", line 155, characters 8-12
          Re-raised at file "lsp/src/logger.ml", line 161, characters 4-19
          Called from file "vendor/cmdliner/src/cmdliner_term.ml", line 25, characters 19-24
          Called from file "vendor/cmdliner/src/cmdliner.ml", line 117, characters 32-39

In general

let t = Mutex.create() in
Mutex.lock t;
Mutex.lock t

on FreeBSD results in Fatal error: exception Sys_error("Mutex.lock: Resource deadlock avoided"), but on Linux it blocks, so I'm not sure if this is something specific to ocaml-lsp, or to ocamlc on FreeBSD.

Reverting to parent of 51f0de6 ("scheduler tweaks") makes this error go away.

@rgrinberg
Copy link
Member

@ulugbekna Mind taking a look? Otherwise we'll just need to revert. Unfortunately, I don't very much about BSD, but would definitely prefer if things worked there.

@ulugbekna
Copy link
Collaborator

I remember we previously discussed this piece of code. I will look into this during the weekend but can't promise I'll be able to solve this. I know little about threads module and BSD.

In my opinion, locking a mutex twice should result in a deadlock; maybe since the second lock is done by the same thread, it is a no-op and just gives some time for the thread to be created (to avoid races, as you said in slack DM). Has removing the second lock resulted in bad behavior of the program previously?

@anuragsoni
Copy link

anuragsoni commented Sep 5, 2020

FWIW ocaml 4.12 might get errorchecking mutex behavior as default and attempting to lock a mutex from the thread that already owns the mutex will raise a Sys_error exception
https://github.com/ocaml/ocaml/pull/9846/files#diff-0ab05a914abe0b1fe88f203ed7bb9bbdR39

@cdaringe
Copy link

cdaringe commented Oct 9, 2020

seeing this error on HEAD, 59c9138--installed today on 4.10.0+multicore

@rgrinberg
Copy link
Member

Could one of you try this on master again? #264 is supposed to fix this I think.

@anuragsoni
Copy link

@rgrinberg I tried this on freebsd and #264 indeed fixes the issue reported here.

@ALPHA-60
Copy link
Author

ALPHA-60 commented Oct 24, 2020

I can confirm that the error is gone when running ocamllsp on 8092592 built with 4.10.1.

@rgrinberg
Copy link
Member

Thanks everyone

rgrinberg added a commit to rgrinberg/opam-repository that referenced this issue Nov 16, 2020
CHANGES:

## Features

- Add keyword completion

- Add go to declaration functionality to jump to a value's specification in a
  .mli file (ocaml/ocaml-lsp#294)

## Fixes

- ocaml/ocaml-lsp#245: correctly use mutexes on OpenBSD (ocaml/ocaml-lsp#264)

- ocaml/ocaml-lsp#268: Do not use vendored libraries when building the lsp package (ocaml/ocaml-lsp#260)

- ocaml/ocaml-lsp#271: Clear diagnostics when files are closed

- Disable non-prefix completion. There's no reliably way to trigger it and it
  can be slow.
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

No branches or pull requests

5 participants