-
Notifications
You must be signed in to change notification settings - Fork 458
Replace IMemoryMappedFileAccessor with null implementation #4573
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.IO.MemoryMappedFiles; | ||
using Microsoft.Azure.WebJobs.Script.Workers.SharedMemoryDataTransfer; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Azure.Functions.Cli.Actions.HostActions; | ||
|
||
/// <summary> | ||
/// A null implementation of MemoryMappedFileAccessor that disables shared memory functionality. | ||
/// This can be used for testing or in environments where shared memory is not supported or desired. | ||
/// </summary> | ||
public class NullMemoryMappedFileAccessor : MemoryMappedFileAccessor | ||
{ | ||
public NullMemoryMappedFileAccessor(ILogger<MemoryMappedFileAccessor> logger) | ||
: base(logger) | ||
{ | ||
Logger.LogDebug("Using NullMemoryMappedFileAccessor - shared memory data transfer is disabled"); | ||
} | ||
|
||
public override bool TryCreate(string mapName, long size, out MemoryMappedFile mmf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a comment can help - "/// Always returns false; no shared memory is created. ///" |
||
{ | ||
mmf = null; | ||
Logger.LogDebug("NullMemoryMappedFileAccessor: TryCreate called for {MapName} with size {Size} - returning false", mapName, size); | ||
return false; | ||
} | ||
|
||
public override bool TryOpen(string mapName, out MemoryMappedFile mmf) | ||
{ | ||
mmf = null; | ||
Logger.LogDebug("NullMemoryMappedFileAccessor: TryOpen called for {MapName} - returning false", mapName); | ||
return false; | ||
} | ||
|
||
public override void Delete(string mapName, MemoryMappedFile mmf) | ||
{ | ||
Logger.LogDebug("NullMemoryMappedFileAccessor: Delete called for {MapName} - no action taken", mapName); | ||
mmf?.Dispose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we care about mmf not being null or not already disposed? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
using Microsoft.Azure.WebJobs.Script.WebHost.Authentication; | ||
using Microsoft.Azure.WebJobs.Script.WebHost.Controllers; | ||
using Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection; | ||
using Microsoft.Azure.WebJobs.Script.Workers.SharedMemoryDataTransfer; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
|
@@ -84,6 +86,9 @@ public IServiceProvider ConfigureServices(IServiceCollection services) | |
|
||
services.AddWebJobsScriptHost(_builderContext.Configuration); | ||
|
||
// Replace the default MemoryMappedFileAccessor with a null implementation | ||
services.Replace(ServiceDescriptor.Singleton<IMemoryMappedFileAccessor, NullMemoryMappedFileAccessor>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fabiocav draft here; still need to consider all the potential impact of disabling this - let me know what you think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think we still want to allow users to test this feature right? So maybe disable by default and add a flag to bring this back in. Or we just don't make a change here and fix it on the host side? |
||
|
||
services.Configure<ScriptApplicationHostOptions>(o => | ||
{ | ||
o.ScriptPath = _hostOptions.ScriptPath; | ||
|
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.
Seal it to prevent unintended extension.