Forums » Development »
[Solved] Question about bus error on file change: Is it a bug?
Added by saf over 14 years ago
Hello,
I posted a bug into Ubuntu launchpad about a bus error in lighttpd:
https://bugs.launchpad.net/ubuntu/+source/lighttpd/+bug/643518
This is an output of strace show this:
ioctl(14, FIONREAD, [0]) = 0 read(14, 0x298dd70, 4159) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(12, EPOLL_CTL_MOD, 14, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=14, u64=14}}) = 0 epoll_ctl(12, EPOLL_CTL_MOD, 14, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=14, u64=14}}) = 0 epoll_wait(12, {{EPOLLIN, {u32=13, u64=13}}}, 10001, 1000) = 1 ioctl(13, FIONREAD, [613]) = 0 read(13, "GET /stats HTTP/1.1\r\nHost: www.t"..., 4159) = 613 setsockopt(13, SOL_TCP, TCP_CORK, [1], 4) = 0 writev(13, [{"HTTP/1.1 200 OK\r\nContent-Type: a"..., 163}], 1) = 163 open("/var/www/trashmail/htdocs/stats", O_RDONLY) = 24 fcntl(24, F_SETFD, FD_CLOEXEC) = 0 mmap(NULL, 26, PROT_READ, MAP_SHARED, 24, 0) = 0x7ff6a72bc000 write(13, "221744625:0.00:1222:36391\n", 26) = -1 EFAULT (Bad address) --- SIGBUS (Bus error) @ 0 (0) --- Process 332 detached
The reason is probably the following:
The file "stats" changed after lighttpd opened the file already and did a mmap on it.
When then lighttpd tried to read the file directly from the memory region with its system call, then lighttpd made a bus error because file changed and its seems that Linux marked the memory region as invalid.
I did not noticed this error on Solaris with its versionned filesystem ZFS. Maybe the behaviour is different on Linux with ext3. I don't know it exactly.
However: We were not sure in the Ubuntu bugs platform if this is a bug? Should lighttpd not output an error or at least exit gracefully?
At the other side I suppose there is not really a solution without loosing of performance because of probabling doing additional system calls and context switchings.
So is it a bug or not that lighttpd produces a bus error on file change while reading?
Replies (2)
RE: Question about bus error on file change: Is it a bug? - Added by stbuehler over 14 years ago
It is a difficult situation... afaik this can always happen if you are using mmap; we would have to code sigbus handlers in all places where mmap is used.
You can prevent this from being a problem if you use "atomic" file updates; write new content to a new file like "file.tmpXXXX" and mv/rename it.
RE: Question about bus error on file change: Is it a bug? - Added by gstrauss over 8 years ago
FYI: fixed in lighttpd 1.4.40, released July 2016.
Latest lighttpd release (at time this is being written) is lighttpd 1.4.44
x-ref: https://bugs.launchpad.net/ubuntu/+source/lighttpd/+bug/643518?comments=all