[erlang-patches] Fix efile_openfile() to handle stat() failure

Mikael Pettersson <>
Wed May 14 17:08:02 CEST 2014


If the initial stat() fails then efile_openfile() will still proceed
to open() the file.  If that succeeds and the caller passed a non-NULL
pSize, then it will copy bogus data from the statbuf into *pSize.  This
has been observed to cause file:read_file/1 to return truncated file
data with no error indication.

The use case involved a large file system mounted via NFS, with some
directories containing large number of files, and NFS mount options
that allow the NFS client to return EIO if the NFS server does not
respond quickly enough.  Depending on the caching state of the client
and server machines, a few stat() calls (fewer than 1 per 10 million)
would take long enough to trigger EIO errors, but subsequent open()
calls would succeed, and read_file/1 would return truncated data.  This
sequence of events has been observed via "strace" on beam.smp.

Signed-off-by: Mikael Pettersson <>

Links:

git fetch git://github.com/mikpe/otp.git openfile-dont-use-undefined-statbuf

https://github.com/mikpe/otp/compare/erlang:maint...openfile-dont-use-undefined-statbuf
https://github.com/mikpe/otp/compare/erlang:maint...openfile-dont-use-undefined-statbuf.patch

https://github.com/erlang/otp/pull/368


More information about the erlang-patches mailing list