-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RecyclableMemoryStream #16949
Use RecyclableMemoryStream #16949
Conversation
I was waiting for Seb reply on the issue to let the author propose the PR, but seems you do it quickly :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very familiar with this API and I don't think we have many actual usages of it. At least not by replacing where we already use MemoryStream, I can explain at Tuesday's meeting.
...rchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellConfigurationSources.cs
Outdated
Show resolved
Hide resolved
...re/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellsSettingsSources.cs
Outdated
Show resolved
Hide resolved
test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/Files/FilesScriptEngine.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure.Abstractions/MemoryStreamFactory.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments but LGTM
src/OrchardCore.Modules/OrchardCore.Media.Indexing.Pdf/Services/PdfMediaFileTextProvider.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure.Abstractions/MemoryStreamFactory.cs
Outdated
Show resolved
Hide resolved
This pull request has merge conflicts. Please resolve those before requesting a review. |
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid these minor breaking changes. We could add the seal suggestion to #16892
src/OrchardCore/OrchardCore.Infrastructure/Scripting/CommonGeneratorMethods.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Infrastructure/Documents/DefaultDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
@MikeAlhayek reverted breaking changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to have broken the database shells feature because the memory stream holding the database shells document is disposed before the configuration source (which uses the memory stream) is actually read.
@@ -53,7 +55,9 @@ public async Task AddSourcesAsync(string tenant, IConfigurationBuilder builder) | |||
{ | |||
var shellSettings = new JsonObject { [tenant] = document.ShellsSettings[tenant] }; | |||
var shellSettingsString = shellSettings.ToJsonString(JOptions.Default); | |||
builder.AddTenantJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(shellSettingsString))); | |||
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(shellSettingsString)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here.
@@ -42,7 +42,9 @@ public async Task AddSourcesAsync(IConfigurationBuilder builder) | |||
if (document.ShellsSettings is not null) | |||
{ | |||
var shellsSettingsString = document.ShellsSettings.ToJsonString(JOptions.Default); | |||
builder.AddTenantJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(shellsSettingsString))); | |||
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(shellsSettingsString)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just updated to OC 2.1 and my (test) site no longer starts. It looks like the problem is this new "using" which results in the stream being disposed when this method exits. The problem is that the stream is added as a configuration source here, but the stream (attached to the configuration source) isn't read until later.
You can see this problem if you enable the database shells feature with OC 2.1. Note that disposing a MemoryStream isn't actually necessary. The Dispose method in MemoryStream does not release any memory, it just marks the stream as closed. So there was no harm in the old code which did not Dispose the stream.
I'll create a separate issue, but I thought it might help to add a comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I wasn't the only one to hit this and it's already been addressed in #17054
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvarblow we release 2.1.1 today with this fix. Please try to upgrade your project and see if the problem is fixed. If not, please open a new issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for releasing the fix so quickly! Yes, that did resolve the issue for me, though I'm now running into another blocking issue with the user timezone service. I'll write up an issue for that one.
@@ -86,7 +86,7 @@ public async Task<IActionResult> Index(string sitemapId, CancellationToken cance | |||
document.Declaration = new XDeclaration("1.0", "utf-8", null); | |||
var stream = new MemoryStream(); | |||
using var stream = MemoryStreamFactory.GetStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not using the Site Map feature, so I can't say whether this is actually a problem, but this looks wrong. With this change, the stream is disposed as it's being returned for use later (by the File result).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvarblow it look suspicious to me too. Feel free to test it out, and submit an issue and PR.
Fix #16946
@sebastienros I am carious to see is RecyclableMemoryStream will have an impact on the project. If you have time to do a comparison that would be awesome.