Skip to content

Commit

Permalink
do not use placeholder worker if ~3 and v2 compatability enabled (#5328)
Browse files Browse the repository at this point in the history
* do not use placeholder worker if ~3 and v2 compatability enabled

* delete irrelevant comment
  • Loading branch information
mhoeger authored and yojagad committed Apr 22, 2020
1 parent 30202a3 commit fe1dfee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/WebJobs.Script/Environment/EnvironmentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ public static bool IsV2CompatibilityMode(this IEnvironment environment)
return isFunctionsV2CompatibilityMode || isV2ExtensionVersion;
}

public static bool IsV2CompatabileOnV3Extension(this IEnvironment environment)
{
string compatModeString = environment.GetEnvironmentVariable(FunctionsV2CompatibilityModeKey);
bool.TryParse(compatModeString, out bool isFunctionsV2CompatibilityMode);

string extensionVersion = environment.GetEnvironmentVariable(FunctionsExtensionVersion);
bool isV3ExtensionVersion = string.Compare(extensionVersion, "~3", CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) == 0;

return isFunctionsV2CompatibilityMode && isV3ExtensionVersion;
}

public static bool IsContainer(this IEnvironment environment)
{
var runningInContainer = environment.GetEnvironmentVariable(RunningInContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ private bool UsePlaceholderChannel(string workerRuntime)
if (!string.IsNullOrEmpty(workerRuntime))
{
// Special case: node apps must be read-only to use the placeholder mode channel
// Also cannot use placeholder worker that is targeting ~3 but has backwards compatibility with V2 enabled
// TODO: Remove special casing when resolving https://github.com/Azure/azure-functions-host/issues/4534
if (string.Equals(workerRuntime, RpcWorkerConstants.NodeLanguageWorkerName, StringComparison.OrdinalIgnoreCase))
{
return _environment.IsFileSystemReadOnly();
// Use if readonly and not v2 compatible on ~3 extension
return _environment.IsFileSystemReadOnly() && !_environment.IsV2CompatabileOnV3Extension();
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,29 @@ public async Task SpecializeAsync_Node_NotReadOnly_KillsProcess()
Assert.Null(initializedChannel);
}

[Fact]
public async Task SpecializeAsync_Node_V2CompatibilityWithV3Extension_KillsProcess()
{
var testMetricsLogger = new TestMetricsLogger();
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, RpcWorkerConstants.NodeLanguageWorkerName);
_testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsV2CompatibilityModeKey, "true");
_testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion, "~3");

_rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger);

IRpcWorkerChannel nodeWorkerChannel = CreateTestChannel(RpcWorkerConstants.NodeLanguageWorkerName);

await _rpcWorkerChannelManager.SpecializeAsync();

// Verify logs
var traces = _testLogger.GetLogMessages();
Assert.True(traces.Count() == 0);

// Verify channel
var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName);
Assert.Null(initializedChannel);
}

[Fact]
public async Task ShutdownStandbyChannels_WorkerRuntime_Not_Set()
{
Expand Down

0 comments on commit fe1dfee

Please sign in to comment.