Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005069OCamlOCaml generalpublic2010-06-08 21:292011-05-12 17:15
Reportermottl 
Assigned To 
PrioritynormalSeveritymajorReproducibilityrandom
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.11.2 
Target VersionFixed in Version3.12.1+dev 
Summary0005069: caml_sys_open may block while holding runtime lock
Descriptioncaml_sys_open in byterun/sys.c uses fcntl to set the FD_CLOEXEC flag (if supported by that platform) on file descriptors after opening a file. Unfortunately, this happens outside of the OCaml runtime lock, which can lead to problems if fcntl blocks.

We have observed this issue when e.g. opening files on NFS. It seems glibc wraps the fcntl system call in a way that requires it to also call "stat", which is known to block under some circumstances.

Could you please change caml_sys_open to call fcntl in the "blocking section" used to open the file? - Thanks!
TagsNo tags attached.
Attached Filespatch file icon pr_5069.patch [^] (683 bytes) 2011-05-10 20:15 [Show Content]

- Relationships

-  Notes
(0005883)
till (reporter)
2011-05-10 20:26

I failed to reproduce this bug and doubt that, as of glibc 2.13, fcntl calls stat while setting FD_CLOSEXEC. The kernel however has a small lock around the fd and it is possible that, on NFS, some operations hold that lock for a bit too long.
The patch to do the fcntl out of the ocaml lock is very simple and probably worth applying just to stray on the safe side.
(0005884)
mottl (reporter)
2011-05-10 21:55

The straces back then definitely showed that fcntl was calling "stat", though the problem might also be due to kernel locks. Hard to say, the problem was not reliably reproducible. Newer glibc versions may also behave differently. I agree we should fix this in any case to be on the safe side.
(0005888)
xleroy (administrator)
2011-05-12 17:15

Ah, the mystery of the blocking fnctl()... The patch is sweet, though, so I applied it in the 3.12 branch. Will be part of 3.12.1.

- Issue History
Date Modified Username Field Change
2010-06-08 21:29 mottl New Issue
2011-05-10 20:15 till File Added: pr_5069.patch
2011-05-10 20:26 till Note Added: 0005883
2011-05-10 21:55 mottl Note Added: 0005884
2011-05-12 17:15 xleroy Note Added: 0005888
2011-05-12 17:15 xleroy Status new => closed
2011-05-12 17:15 xleroy Resolution open => fixed
2011-05-12 17:15 xleroy Fixed in Version => 3.12.1+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker