janestreet / janestreet/memtrace
Shared_writer_fd.close leaves its mutex locked after a successful close
- Dominant language
- OCaml
- Stars
- 87
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
`Buf.Shared_writer_fd.close` acquires `t.lock`, marks the descriptor closed, and calls `Unix.close`. The mutex is currently unlocked only inside the exception handler for `Unix.close`.
On the normal successful path, `close` returns with the mutex still held. Any later `write_fully` call blocks while trying to acquire the lock instead of observing `Closed`. A second `close` blocks for the same reason. This can also leave a writer queued forever if it races with shutdown.
The close error is intentionally ignored, but the lock release should happen regardless of whether `Unix.close` succeeds. I have a small patch ready that puts the best-effort close inside `Fun.protect` and adds a regression covering `close` followed by `write_fully`.
Contributor guide
Research direction
Start at Buf.Shared_writer_fd.close and trace its lock handling around Unix.close and Fun.protect. Verify completion with a regression covering close followed by write_fully on the successful-close path, ensuring later operations do not block.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100