2

Currently, I am facing two issues in the Azure function app. I have provided the details below:

1. Global variable content is being shared across executions: I have used Concurrent dictionary which is a global variable, private and static. This variable is being used in the Queue Trigger.

private static readonly ConcurrentDictionary<string, string> s_mapping = new ConcurrentDictionary<string, string>()

Intermittently, I see that the above variable is being shared across different Queue trigger executions. How can I rectify it, so that the variables are not shared across different run instances?

2. Old code running after publish through Visual studio: I publish the code using visual studio, intermittently I see that the old code is running. In the configuration, WEBSITE_RUN_FROM_PACKAGE is set as 1 and also I deploy it as a zip file from VS. I tried restarting the Function App but it doesn't seem to work.

Really appreciate the help here or any guidance on what can be done for these issues.

PriyankaB
  • 65
  • 1
  • 2
  • 7

1 Answers1

2

Each function app runs in its own process and all functions run in that process. Static variables are shared across all functions in that application just as if you'd written an ASP.NET or console app. For example, you can create an HttpClient in a static class and all functions can access that same client instance (we encourage this, in fact). It's always been this way, so nothing changed there.

Source: https://github.com/Azure/Azure-Functions/issues/1202

1-) don't use static variables or split into different azure function apps.

2-) try removing files from wwwroot before publishing new code. This should not happen, but it's possible in case of high workloads (code being processed while you're publishing new code). I believe the best you can do is to proper setup a cleaning step before pushing changes.

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Thanks a lot for the response. For the first issue, I have only one Azure function app with two azure functions (HTTP & Queue Trigger). Dictionary is being used in the Queue Trigger only. To elaborate, 1st call HTTP Trigger gets triggered which triggers the Queue Trigger, 1st call completes. In the second call, I see the dictionary content of the 1st call in the Queue Trigger. I will remove the static and check if the issue gets resolved. For the second issue, I tried deleting the files inside the wwwroot, I get 404 not found. Might be due to the zip file published from VS. – PriyankaB Aug 03 '21 at 04:35
  • 1
    1-) yes, if you don't want to share the content of the dictionary, just remove the static and it will work. 2-) Stop the function app, change the value "RUN_FROM_PACKAGE" to 0. Delete the files, then switch the value to 1 again and start the function app. – Thiago Custodio Aug 03 '21 at 12:52