diff --git a/src/FunctionLoader.cs b/src/FunctionLoader.cs
index 4c2e1064..c16faa70 100644
--- a/src/FunctionLoader.cs
+++ b/src/FunctionLoader.cs
@@ -36,6 +36,14 @@ internal static AzFunctionInfo GetFunctionInfo(string functionId)
throw new InvalidOperationException(string.Format(PowerShellWorkerStrings.FunctionNotLoaded, functionId));
}
+ ///
+ /// Returns true if the function with the given functionId is already loaded.
+ ///
+ public static bool IsLoaded(string functionId)
+ {
+ return LoadedFunctions.ContainsKey(functionId);
+ }
+
///
/// This method runs once per 'FunctionLoadRequest' during the code start of the worker.
/// It will always run synchronously because we process 'FunctionLoadRequest' synchronously.
diff --git a/src/RequestProcessor.cs b/src/RequestProcessor.cs
index d72815c5..e5ca4e16 100644
--- a/src/RequestProcessor.cs
+++ b/src/RequestProcessor.cs
@@ -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).