Skip to content

Commit 82cedee

Browse files
authored
Ignore function load requests with duplicate FunctionId values (#278) (#279)
* Add FunctionLoader IsLoaded method * Return from ProcessFunctionLoadRequest early if already loaded
1 parent a4db092 commit 82cedee

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/FunctionLoader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ internal static AzFunctionInfo GetFunctionInfo(string functionId)
3636
throw new InvalidOperationException(string.Format(PowerShellWorkerStrings.FunctionNotLoaded, functionId));
3737
}
3838

39+
/// <summary>
40+
/// Returns true if the function with the given functionId is already loaded.
41+
/// </summary>
42+
public static bool IsLoaded(string functionId)
43+
{
44+
return LoadedFunctions.ContainsKey(functionId);
45+
}
46+
3947
/// <summary>
4048
/// This method runs once per 'FunctionLoadRequest' during the code start of the worker.
4149
/// It will always run synchronously because we process 'FunctionLoadRequest' synchronously.

src/RequestProcessor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
146146
out StatusResult status);
147147
response.FunctionLoadResponse.FunctionId = functionLoadRequest.FunctionId;
148148

149+
// The worker may occasionally receive multiple function load requests with
150+
// the same FunctionId. In order to make function load request idempotent,
151+
// the worker should ignore the duplicates.
152+
if (FunctionLoader.IsLoaded(functionLoadRequest.FunctionId))
153+
{
154+
// If FunctionLoader considers this function loaded, this means
155+
// the previous request was successful, so respond accordingly.
156+
return response;
157+
}
158+
149159
// When a functionLoadRequest comes in, we check to see if a dependency download has failed in a previous call
150160
// or if PowerShell could not be initialized. If this is the case, mark this as a failed request
151161
// and submit the exception to the Host (runtime).

0 commit comments

Comments
 (0)