Skip to content

Conversation

@MichelJansson
Copy link
Contributor

Releases/revokes objectURL of original image (sent to toImageFile) after it has been loaded, as it is no longer needed after that point.

No automated tests added, as there is no simple way (without overriding APIs anyway) to find/get existing objectURL's.
Manual testing however shows that the URL's are released by;

  1. Using the sample outlined in Blazor InputFile RequestImageFileAsync not revoking ObjectURL #35156
  2. Inspect page with DevTools, finding object URL's in the sources tab
  3. Trying to open any of the URL's (open in new tab) -> ERR_FILE_NOT_FOUND

Fixes #35156

@MichelJansson MichelJansson requested a review from a team as a code owner August 19, 2021 13:33
@ghost ghost added area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member labels Aug 19, 2021
@dnfadmin
Copy link

dnfadmin commented Aug 19, 2021

CLA assistant check
All CLA requirements met.

@TanayParikh TanayParikh self-assigned this Aug 19, 2021
Copy link
Contributor

@TanayParikh TanayParikh left a comment

Choose a reason for hiding this comment

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

Thanks @MichelJansson, this looks good to me. cc/ @MackinnonBuck as he was the original author in this area so would like to get his take.

@MichelJansson
Copy link
Contributor Author

@TanayParikh, Thanks for checking. I read somewhere that the main branch now was targeting .NET 7, is that correct? If so, should we change the target branch to one relevant for 6-rc2?

@TanayParikh
Copy link
Contributor

@TanayParikh, Thanks for checking. I read somewhere that the main branch now was targeting .NET 7, is that correct? If so, should we change the target branch to one relevant for 6-rc2?

From my understanding the main branch should still be appropriate for rc2 targeted patches, I'll update if I find out otherwise.

@MackinnonBuck
Copy link
Member

@TanayParikh This looks good to me as well

@TanayParikh TanayParikh enabled auto-merge (squash) August 24, 2021 23:01
@TanayParikh
Copy link
Contributor

Did some quick additional manual validations, things are looking good, ready to merge! Thanks again @MichelJansson

const loadedImage = await new Promise(function(resolve: (loadedImage: HTMLImageElement) => void): void {
const originalFileImage = new Image();
originalFileImage.onload = function(): void {
URL.revokeObjectURL(originalFileImage.src);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also do this onerror? Is there an opportunity for that to happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I guess it would error out if the file sent wasn't an image?

@TanayParikh - Looks like the compiled dist/Release/blazor.*.js files didn't get this last update. From my understanding those also has to be committed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea. I guess it would error out if the file sent wasn't an image?

More so if the image doesn't exist at all:
https://www.w3schools.com/jsref/event_onerror.asp

@TanayParikh - Looks like the compiled dist/Release/blazor.*.js files didn't get this last update. From my understanding those also has to be committed?

Usually yes, however given the final change wouldn't have any effect on tests, updating the file isn't strictly necessary here (I also didn't have push permissions via git due to this branch being on a separate fork, only could make changes via GitHub UI). Regardless, the update will be picked up automatically via the next change-set. Good eye though! 😄

@TanayParikh TanayParikh merged commit 4b48d6f into dotnet:main Aug 25, 2021
@ghost ghost added this to the 7.0-preview1 milestone Aug 25, 2021
@TanayParikh
Copy link
Contributor

/backport to release/6.0

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@TanayParikh backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Release object URL after image for resize has loaded
warning: Cannot merge binary files: src/Components/Web.JS/dist/Release/blazor.server.js (HEAD vs. Release object URL after image for resize has loaded)
Using index info to reconstruct a base tree...
M	src/Components/Web.JS/dist/Release/blazor.server.js
Falling back to patching base and 3-way merge...
Auto-merging src/Components/Web.JS/dist/Release/blazor.server.js
CONFLICT (content): Merge conflict in src/Components/Web.JS/dist/Release/blazor.server.js
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Release object URL after image for resize has loaded
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

TanayParikh added a commit that referenced this pull request Aug 25, 2021
wtgodbe pushed a commit that referenced this pull request Aug 25, 2021
…` to 6.0 (#35712)

* Release object URL after image for resize has loaded (#35499)

Co-authored-by: Tanay Parikh <[email protected]>

* Updated release.js files

Co-authored-by: Michel Jansson <[email protected]>
@MikeReedGH
Copy link

Hi All,

This error still appears to be happening in a .Net 7 Blazor WASM PWA app :(

After calling e.File.RequestImageFileAsync I can see the blob is created in the chrome sources tab.
For each file I select a blob is created. They never disappear from the sources tab unless I refresh (f5) the page.
If I don't use the e.File.RequestImageFileAsync but rather just the e.File.OpenReadStream(e.File.Size) then the blob is not created at all, and so the memory leak does not occur.

Will the fix mentioned above made it's way into the .Net 7 release?

I am running as a client side Blazor WASM/PWA and therefore internally navigating between pages rather than just a traditional redirect in the browser, could that mean that the revokeObjectURL is never called?

Thanks and Regards

@MichelJansson
Copy link
Contributor Author

Hi All,

This error still appears to be happening in a .Net 7 Blazor WASM PWA app :(

After calling e.File.RequestImageFileAsync I can see the blob is created in the chrome sources tab. For each file I select a blob is created. They never disappear from the sources tab unless I refresh (f5) the page. If I don't use the e.File.RequestImageFileAsync but rather just the e.File.OpenReadStream(e.File.Size) then the blob is not created at all, and so the memory leak does not occur.

Will the fix mentioned above made it's way into the .Net 7 release?

I am running as a client side Blazor WASM/PWA and therefore internally navigating between pages rather than just a traditional redirect in the browser, could that mean that the revokeObjectURL is never called?

Thanks and Regards

@MikeReedGH The fix was implemented into .NET6 so should also have been released with .NET7. I can still see the fix in the main branch.

If i remember correctly, the blobs will still be visible under the sources tab even though they have been released. Try and open the URL's from the sources tab to see if they actually still exist (.3 of the manual testing suggested in the PR description)

@MikeReedGH
Copy link

@MichelJansson. Thanks for replying. Ah ok, so the blobs still showing may just be a red herring!? I'll check.

I do still have the problem....as soon a user selects a photo/or takes a camera photo that the WASM app just immediately crashes and restarts. It's not a silly bug in my handling of the IBrowserFile. I have quadrupled checked.
It happens seemingly randomly, it will work fine for hours and then suddenly just crash.
It just smells like a memory leak, and I really thought I had found it when reading about this bug.
I am running out of ideas :(

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor InputFile RequestImageFileAsync not revoking ObjectURL

6 participants