Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybind/rados: fix object lifetime issues and other bugs in aio #7778

Merged
merged 2 commits into from Mar 1, 2016

Commits on Feb 24, 2016

  1. pybind/rados: Fix error handling and leaks in aio

    aio_read:
    The reference to ret_s begins existing at PyBytes_FromStringAndSize and
    is handed over to the callback if rados_aio_read succeeds. This creates
    a lot of subtle scenarios where it might not be XDECREFed (e.g. if
    a KeyboardInterrupt arrives at the wrong time). Instead, store the pointer
    to that buffer in the completion object, and hand over responsibility for
    the XDECREF to it. This guarantees that the "special" reference to this
    incomplete object will be released when the completion object is
    deallocated.
    
    Also make sure we don't try to _PyBytes_Resize with a negative length.
    
    Add a failure case to the aio_read test in test_rados.py
    
    Completion: the wrapper methods weren't being called, which prevents
    the completion objects from being freed until the Ioctx is. Fix this
    and add a refcount check to the aio_read test.
    
    Signed-off-by: Hector Martin <marcan@marcan.st>
    marcan committed Feb 24, 2016
    Configuration menu
    Copy the full SHA
    3c767ab View commit details
    Browse the repository at this point in the history
  2. pybind/rados: track completions before calling aio functions

    Tracking completions is critical for memory safety - if the
    aio function succeeds, the completion must be tracked. However,
    if a KeyboardInterrupt or similar arrives between the call and
    the tracking, the completion will not be tracked.
    
    Fix this by tracking the completion before the aio call, and
    explicitly cleaning up in the failure case.
    
    This leaves the opposite problem, where an unexpected exception
    (other than simple error return from the aio function) will cause
    the completion to not be freed until the Ioctx is destroyed, but
    that is a relatively minor issue.
    
    Signed-off-by: Hector Martin <marcan@marcan.st>
    marcan committed Feb 24, 2016
    Configuration menu
    Copy the full SHA
    6e901ba View commit details
    Browse the repository at this point in the history