Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

pyximport: fix a bug crashing other processes #188

Merged
merged 1 commit into from

2 participants

@pv
pv commented

pyxbuild overwrites .so file contents, corrupting any mmapped code image
loaded. If pyximporting the same module from two different processes, on
Linux this leads to crashes with bus error.

This commit fixes the issue by unlinking the file first. On Linux et
al., this does not change the file contents of any open FDs. On
Windows, unlinking fails, and we just switch to using a different file
name.

@pv pv pyximport: fix a bug crashing other processes
pyxbuild overwrites .so file contents, corrupting any mmapped code image
loaded. If pyximporting the same module from two different processes, on
Linux this leads to crashes with bus error.

This commit fixes the issue by unlinking the file first. On Linux et
al., this does not change the file contents of any open FDs.  On
Windows, unlinking fails, and we just switch to using a different file
name.
e2f2580
@scoder
Owner

Makes sense to me. Thanks!

@scoder scoder merged commit e682668 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2013
  1. @pv

    pyximport: fix a bug crashing other processes

    pv authored
    pyxbuild overwrites .so file contents, corrupting any mmapped code image
    loaded. If pyximporting the same module from two different processes, on
    Linux this leads to crashes with bus error.
    
    This commit fixes the issue by unlinking the file first. On Linux et
    al., this does not change the file contents of any open FDs.  On
    Windows, unlinking fails, and we just switch to using a different file
    name.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 0 deletions.
  1. +11 −0 pyximport/pyxbuild.py
View
11 pyximport/pyxbuild.py
@@ -124,6 +124,17 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0,
basename + '.reload%s'%count)
try:
import shutil # late import / reload_support is: debugging
+ try:
+ # Try to unlink first --- if the .so file
+ # is mmapped by another process,
+ # overwriting its contents corrupts the
+ # loaded image (on Linux) and crashes the
+ # other process. On Windows, unlinking an
+ # open file just fails.
+ if os.path.isfile(r_path):
+ os.unlink(r_path)
+ except OSError:
+ continue
shutil.copy2(org_path, r_path)
so_path = r_path
except IOError:
Something went wrong with that request. Please try again.