Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

Don't capture AsyncLocals to PhysicalFilesWatcher - #334

Closed
benaadams wants to merge 2 commits into
aspnet:release/2.2from
benaadams:asynclocals
Closed

Don't capture AsyncLocals to PhysicalFilesWatcher#334
benaadams wants to merge 2 commits into
aspnet:release/2.2from
benaadams:asynclocals

Conversation

@benaadams

@benaadams benaadams commented Aug 26, 2018

Copy link
Copy Markdown

This causes a problem with IHttpContextAccessor as it captures the HttpContext and everything linked to it causing a lot of memory to become rooted (as seen in https://github.com/aspnet/KestrelHttpServer/issues/2840#issuecomment-416034872)

image

/cc @davidfowl

Comment thread src/FS.Physical/PhysicalFilesWatcher.cs Outdated
_fileWatcher.Renamed += OnRenamed;
_fileWatcher.Deleted += OnChanged;
_fileWatcher.Error += OnError;
// Don't capture the current ExecutionContext and its AsyncLocals onto the token registration causing them to live forever

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

event registration

@benaadams

Copy link
Copy Markdown
Author

Will only capture on linux (due to cancellation token) issue on Windows is due to the ChangeTokens (addressed elsewhere)

@benaadams benaadams closed this Aug 27, 2018
@HassanHashemi

HassanHashemi commented Aug 27, 2018

Copy link
Copy Markdown

Will only capture on linux

where is this addressed? because this one is closed.

@benaadams

Copy link
Copy Markdown
Author

For linux I raised an issue https://github.com/dotnet/corefx/issues/31973

However all the FileSystemWatcher roots on your trace should be fixed by dotnet/extensions#392

@benaadams
benaadams deleted the asynclocals branch August 27, 2018 11:47
@benaadams
benaadams restored the asynclocals branch September 24, 2018 23:14
@benaadams benaadams reopened this Sep 24, 2018
@pranavkm

Copy link
Copy Markdown
Contributor

@benaadams this should be fixed by the use of 32dbcac.

@benaadams

Copy link
Copy Markdown
Author

@benaadams this should be fixed by the use of 32dbcac.

Different capturing; its captured onto the FileSystemWatcher when the events are enabled with _fileWatcher.EnableRaisingEvents = true; https://github.com/dotnet/corefx/issues/31973#issuecomment-424083196

Unfortunately I can't write a test for it as ASP.NET Core now registers the callback as a cancellation token with the flow suppressed dotnet/extensions#392; so while it captures it; it doesn't flow it back to be observable :-/

/cc @stephentoub

restoreFlow = true;
}

// Perf: Turn off the file monitoring if no files to monitor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This comment is terrible

@mkArtakMSFT

Copy link
Copy Markdown

Thank you for your effort. As part of the effort to reduce the number of repositories we're going to move the code of this repo to https://github.com/aspnet/aspnetcore repo. Feel free to resubmit a new PR in the target repo as we're closing this PR now.

@mkArtakMSFT mkArtakMSFT closed this Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants