Skip to content

Clean file descriptor and memory leaks - #1317

Merged
mrocklin merged 25 commits into
dask:masterfrom
mrocklin:test-travis
Aug 11, 2017
Merged

mrocklin merged 25 commits into
dask:masterfrom
mrocklin:test-travis

Conversation

@mrocklin

@mrocklin mrocklin commented Aug 7, 2017

Copy link
Copy Markdown
Member

No description provided.

@mrocklin

mrocklin commented Aug 9, 2017

Copy link
Copy Markdown
Member Author

@pitrou if you have a moment can you take a look at the failures in travis for this PR? We're getting out of memory errors on master when forking new processes.

@mrocklin

mrocklin commented Aug 9, 2017

Copy link
Copy Markdown
Member Author

It looks like we're leaking file descriptors

@mrocklin mrocklin changed the title Trivial change to trigger travis-ci Clean file descriptor and memory leaks Aug 10, 2017
Comment thread distributed/process.py Outdated
@classmethod
def _watch_process(cls, selfref, process, state, q):
r = repr(selfref())
while True:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason to poll here instead of simply waiting for the exit with process.join?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now use process.join after we poll for when the process starts. We could probably do this more cleanly, but I'm going to punt for now.

Comment thread distributed/process.py Outdated
pass
while True:
# Periodic poll as there's no simple way to poll a threading Queue
# and a mp Process at the same time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now obsolete, no?

@pwaller

pwaller commented Aug 11, 2017

Copy link
Copy Markdown
Contributor

There is a method, _do_start which now appears upon reading to be dead code - I guess it was dead before this PR but complicates understanding what's happening. Likewise with _do_terminate.

I assume the poll for process start is because you can't process.join a process before it has started?

A more straightforward architecture to analyse would be to start the process watcher thread once process.start() has been called, then the watcher a life cycle that better matches the process (rather than starting when the AsyncProcess is created).

My suggestion would be to move the _watch_process_thread construction out of __init__ -> _start_threads and instead do it immediately after process.start() in _watch_message_queue.start. Then the watcher the thread can go straight into process.join.

@mrocklin

Copy link
Copy Markdown
Member Author

I've removed _do_start/terminate and moved thread-starting until after we start the process.

@mrocklin
mrocklin merged commit 4fc2dbd into dask:master Aug 11, 2017
@mrocklin
mrocklin deleted the test-travis branch August 11, 2017 15:26
Comment thread distributed/process.py
_process_one_message(timeout=1e6)
except SystemExit:
return
q.put({'op': 'stop'})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happens if e.g. someone calls terminate after the process has stopped and you have stopped the message queue thread?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't immediately see an issue here. All {'op': 'stop'} does is stop the message queue thread, so this wouldn't have a large impact. You know this part of the code better than I do though. If you see something amiss then please speak up.

Comment thread distributed/process.py
r = repr(selfref())
process.join()
exitcode = process.exitcode
if exitcode is not None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should always be true after join(), so you can turn this into an assert.

Comment thread distributed/process.py
state.exitcode = exitcode
# Make sure the process is removed from the global list
# (see _children in multiprocessing/process.py)
process.join(timeout=0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join() was already called above, so it's pointless to call it again :-)

Comment thread distributed/process.py

thread = threading.Thread(
target=AsyncProcess._watch_process,
name="AsyncProcess %s watch" % name,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a slightly different name for the two auxiliary threads :-)

@pitrou

pitrou commented Aug 11, 2017

Copy link
Copy Markdown
Member

I took a brief look at the AsyncProcess changes (see comments).

mrocklin added a commit to mrocklin/distributed that referenced this pull request Aug 11, 2017
We did a hasty merge in dask#1317 .  This includes a few follow on changes.
@mrocklin

Copy link
Copy Markdown
Member Author

Thanks for the feedback @pitrou . Some of these are handled in #1324

mrocklin added a commit to mrocklin/distributed that referenced this pull request Aug 11, 2017
We did a hasty merge in dask#1317 .  This includes a few follow on changes.
mrocklin added a commit that referenced this pull request Aug 14, 2017
* Clean up AsyncProcess handling

We did a hasty merge in #1317 .  This includes a few follow on changes.

* add failing test

* remove {'op': 'stop'} message
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.

3 participants