-
Notifications
You must be signed in to change notification settings - Fork 107
Fix issue when isolating libraries when file not ready #854
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
Conversation
Adding namespace import scenarios Ensure changes Add unittests Amend test cases Fix an issue when customer defines a module with collided name Fix test_paths_resolution Fix case
6f43ad1
to
8ac6543
Compare
Validation: Without the fix from Azure/azure-functions-python-library#90: With the fix from Azure/azure-functions-python-library#90: Tested with the following mesh docker image and command: .\run_host_mesh_custom.ps1 -ImageName mcr.microsoft.com/azure-functions/mesh:3.0.15828-python3.9 -PythonVersion 3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments.
LGTM
@@ -480,7 +483,7 @@ async def _handle__function_environment_reload_request(self, req): | |||
) | |||
|
|||
# Reload azure google namespaces | |||
DependencyManager.reload_azure_google_namespace( | |||
DependencyManager.reload_customer_libraries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the # Reload azure google namespaces
comment here. Not needed.
@@ -18,6 +18,7 @@ | |||
|
|||
# Platform Environment Variables | |||
AZURE_WEBJOBS_SCRIPT_ROOT = "AzureWebJobsScriptRoot" | |||
CONTAINER_NAME = "CONTAINER_NAME" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this constant in dependency.py itself? This isn't being used globally.
if cx_working_dir: | ||
working_directory: str = os.path.abspath(cx_working_dir) | ||
if not working_directory: | ||
working_directory = cls.cx_working_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there ever be a case that cx_working_dir isn't a property in cls?
# The modules defined in customer's working directory should have the | ||
# least priority since we uses the new folder structure. | ||
# Please check the "Message to customer" section in the following PR: | ||
# https://github.com/Azure/azure-functions-python-worker/pull/726 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make a pinned issue as well (or check if this is added to Python Dev Docs itself)?
|
||
@classmethod | ||
def reload_azure_google_namespace(cls, cx_working_dir: str): | ||
def reload_customer_libraries(cls, cx_working_dir: str): | ||
"""Reload azure and google namespace, this including any modules in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not only doing Azure and Google right? Comment should reflect this now.
@@ -12,7 +12,10 @@ steps: | |||
inputs: | |||
disableAutoCwd: true | |||
scriptPath: 'pack/scripts/nix_deps.sh' | |||
# The following task is disabled since Python 3.9 to fix azure/ namespace | |||
# https://github.com/Azure/azure-functions-python-worker/pull/854 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we re-enable this particular task later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is an actual fix for Python 3.9 and afterward.
|
||
|
||
def main(req: func.HttpRequest) -> func.HttpResponse: | ||
"""This function is an HttpTrigger to check if the modules are loaded from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test! :)
@Hazhzeng Currently the mitigation provided works to avoid 404 errors. Any update on when this fix is expected to roll out to the production so that the app setting 'PYTHON_ISOLATE_WORKER_DEPENDENCIES ' can be removed? |
The fix is currently being rolled out and is halfway across all our fleet. It should be completed by mid-next week to all the geo-locations. |
Once the fix is deployed, we can remove the setting 'PYTHON_ISOLATE_WORKER_DEPENDENCIES' to 0 right? (or) do we need to retain it in the app settings? |
Description
Fixes an issue in Python 3.9 Linux Consumption plan. This occurs when the customer's
azure.functions
library is not presented as we tried to clear out its cache prematurely. This will result in a longer cold start time since the function host will restart several times to wait for the customer's content before doing specialization. The worst scenario will cause the website goes into a 404 state for a few seconds during the code start.Discussion
Mitigation
This is currently impacting the customers using Python 3.9 Linux Consumption. Setting the
PYTHON_ISOLATE_WORKER_DEPENDENCIES
to0
will mitigate this issue for now.Validation:
pytest --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch .\tests\unittests\test_extension.py .\tests\unittests\test_utilities_dependency.py --randomly-seed=3973973583
to introduce unexpected module loading order. This should fails withazure.functions key not found
before this fix.Also found that improper namespacing in worker nuget artifact:
The __init__.py file should only be placed in https://github.com/Azure/azure-functions-python-library source code. However, this shouldn't be included in a release package.

According to Python namespace specification https://www.python.org/dev/peps/pep-0420/#specification. Quote:
PR information
Quality of Code and Contribution Guidelines