Skip to content

PYTHON-644#686

Closed
mambocab wants to merge 2 commits into
apache:masterfrom
mambocab:PYTHON-644
Closed

PYTHON-644#686
mambocab wants to merge 2 commits into
apache:masterfrom
mambocab:PYTHON-644

Conversation

@mambocab

Copy link
Copy Markdown
Contributor

This change adds a sentinel to indicate when a ResponseFuture's timer has been cancelled. This is similar to #685, but also uses a lock to eliminate race conditions. For instance, the lock prevents this series of events:

  1. timer calls _on_speculative_execute on thread 1
  2. _set_final_result cancels the timer on thread 2
  3. _on_speculative_execute starts a new timer on thread 1

With these changes, I have not produced memory leaks with the script provided in PYTHON-644 when running it locally many times.

@aholmberg and I both suspect that there's a better solution than explicit locking, but I haven't figured it out yet.

This does not eliminate, but it shrinks, the window for the race
condition that caused PYTHON-644. In this race, _set_result could be
called from the event loop before send_request calls _start_timer.

The goal of the _CANCELLED sentinel is to allow permanent cancelling of
all future timers for a given ResponseFuture. Unfortunately, there's
still a race -- if _timer is cancelled during _start_timer.
@mambocab

Copy link
Copy Markdown
Contributor Author

Closing this PR for now, while I investigate a lockless solution that Adam suggested.

@mambocab mambocab closed this Jan 12, 2017
@mambocab mambocab deleted the PYTHON-644 branch February 14, 2017 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant