Skip to content

Ignore function load requests with duplicate FunctionId values #278

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/FunctionLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ internal static AzFunctionInfo GetFunctionInfo(string functionId)
throw new InvalidOperationException(string.Format(PowerShellWorkerStrings.FunctionNotLoaded, functionId));
}

/// <summary>
/// Returns true if the function with the given functionId is already loaded.
/// </summary>
public static bool IsLoaded(string functionId)
{
return LoadedFunctions.ContainsKey(functionId);
}

/// <summary>
/// This method runs once per 'FunctionLoadRequest' during the code start of the worker.
/// It will always run synchronously because we process 'FunctionLoadRequest' synchronously.
Expand Down
10 changes: 10 additions & 0 deletions src/RequestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
out StatusResult status);
response.FunctionLoadResponse.FunctionId = functionLoadRequest.FunctionId;

// The worker may occasionally receive multiple function load requests with
// the same FunctionId. In order to make function load request idempotent,
// the worker should ignore the duplicates.
if (FunctionLoader.IsLoaded(functionLoadRequest.FunctionId))
{
// If FunctionLoader considers this function loaded, this means
// the previous request was successful, so respond accordingly.
return response;
}

// When a functionLoadRequest comes in, we check to see if a dependency download has failed in a previous call
// or if PowerShell could not be initialized. If this is the case, mark this as a failed request
// and submit the exception to the Host (runtime).
Expand Down