Skip to content

Close connection comm on retry - #3365

Merged
jrbourbeau merged 2 commits into
dask:masterfrom
Quansight-Labs:close-comm-on-retry
Jan 13, 2020
Merged

Close connection comm on retry#3365
jrbourbeau merged 2 commits into
dask:masterfrom
Quansight-Labs:close-comm-on-retry

Conversation

@jrbourbeau

Copy link
Copy Markdown
Member

Currently when making new comm connections, we do so with gen.with_timeout here

comm = await gen.with_timeout(
timedelta(seconds=min(deadline - time(), 1)),
future,
quiet_exceptions=EnvironmentError,
)

and retry the connection if a timeout is reached. However, gen.with_timeout does not cancel a task when it's timeout expires. Not cancelling these tasks can lead to a "Closing dangling stream" warning being raised here

logger.warning("Closing dangling stream in %s" % (r,))

when TCP class instances from previously timed out connection task are garbage collected.

Switching to asyncio.wait_for allows us to keep a similar timeout-then-retry connection behavior, but also cancels a connection task if a timeout occurs.

This is just one proposed improvement to the situation. Alternatively we could make the currently hardcoded 1s in the timeout configurable.

@mrocklin

Copy link
Copy Markdown
Member

This seems fine to me. Should we swap out gen.with_timeout generally throughout the codebase?

cc also @jcrist , who has been interested in tornado/asyncio switching code in the past.

@mrocklin

Copy link
Copy Markdown
Member

Also, thanks for hunting this down @jrbourbeau !

@jcrist

jcrist commented Jan 11, 2020

Copy link
Copy Markdown
Member

This looks good to me, thanks @jrbourbeau. Merging.

Should we swap out gen.with_timeout generally throughout the codebase?

I think we should strive for that, but because it has different semantics replacing it isn't always straightforward. Each case needs to be examined to determine what the intent was and if the lack of cancellation was accidental or necessary.

@jcrist

jcrist commented Jan 11, 2020

Copy link
Copy Markdown
Member

Oop, just saw you marked this as [WIP]. I'll let you merge when you're happy with things. The fix looks good to me as is though.

@jrbourbeau jrbourbeau changed the title [WIP] Close connection comm on retry Close connection comm on retry Jan 13, 2020
@jrbourbeau

Copy link
Copy Markdown
Member Author

Thanks for feedback @mrocklin @jcrist! Merging this now

I opened up a separate issue (#3367) for tracking gen.with_timeout -> asyncio.wait_for switches more broadly throughout the codebase

@jrbourbeau
jrbourbeau merged commit d586483 into dask:master Jan 13, 2020
@jrbourbeau
jrbourbeau deleted the close-comm-on-retry branch January 13, 2020 18:48
bnaul pushed a commit to replicahq/distributed that referenced this pull request Feb 10, 2020
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