Skip to content

Commit

Permalink
Ignore function load requests with duplicate FunctionId values (#278) (
Browse files Browse the repository at this point in the history
…#279)

* Add FunctionLoader IsLoaded method

* Return from ProcessFunctionLoadRequest early if already loaded
  • Loading branch information
AnatoliB authored Jul 16, 2019
1 parent a4db092 commit 82cedee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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 @@ -146,6 +146,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

0 comments on commit 82cedee

Please sign in to comment.