[issue19337] MMAP: Bus error (core dump) under heavy read/write
New submission from Ribhi Kamal: I was about to use memory mapping for something when I discovered that the code example posted on python.org causes python to core dump. %100 reproducible The steps are really simple. 1- Create a file and map it using mmap.mmap 2- In a while loop, contintously read the file 3- From another process, like bash, continuously write to the file. After about 5 iterations from the reader, python core dumps. Reader code (python): #!/usr/bin/python2.7 import mmap import time with open(hello.txt, wb) as f: f.write(Hello Python! 1234123412341234\n) with open(hello.txt, r+b) as f: # memory-map the file, size 0 means whole file mm = mmap.mmap(f.fileno(), 0) count=0 while count 100: mm.seek(0) print mm.readline() time.sleep(0.1) count = count + 1 # close the map mm.close() Writer code (linux shell/bash): #!/bin/bash count=0 while true do ((count++)) echo $count hello.txt done Now run the reader, then launch the writer in a terminal. In my case I get the following output: 110 462 Bus error (core dumped) Python 2.7.3 Linux 3.2.0-54-generic #82-Ubuntu SMP Tue Sep 10 20:09:12 UTC 2013 i686 i686 i386 GNU/Linux Ubuntu 12.04.3 LTS Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz -- components: IO messages: 200820 nosy: rbhkamal priority: normal severity: normal status: open title: MMAP: Bus error (core dump) under heavy read/write type: crash versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Changes by STINNER Victor victor.stin...@gmail.com: -- nosy: +haypo, neologix, pitrou, sbt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Ribhi Kamal added the comment: Code dump attached -- Added file: http://bugs.python.org/file32285/core.gz ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Serhiy Storchaka added the comment: Confirm on 2.7 and 3.x. -- components: +Library (Lib) nosy: +serhiy.storchaka versions: +Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Charles-François Natali added the comment: 3- From another process, like bash, continuously write to the file. That's the problem: reducing (actually truncating in your case) a file currently mmaped *can only result in a core dump*: when you try to read from a location in memory which doesn't correspond anymore to a position in the file (since it got truncated), which value could the kernel return? The page you're trying to read from isn't mapped anymore, so you get a segfault. Apparently it's even documented in the main page: The effect of changing the size of the underlying file of a mapping on the pages that correspond to added or removed regions of the file is unspecified. -- resolution: - invalid stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Ribhi Kamal added the comment: I figured I was doing something wrong... sorry about that -- components: -Library (Lib) resolution: invalid - status: closed - open versions: -Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Changes by Ribhi Kamal rbhka...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Changes by Ribhi Kamal rbhka...@gmail.com: Removed file: http://bugs.python.org/file32285/core.gz ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19337] MMAP: Bus error (core dump) under heavy read/write
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19337 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com