Azure Functions directory read-only on Linux

Thomas Ligon (Office 365) 26 Reputation points
2022-09-11T15:31:10.653+00:00

I am getting an error
Exception while executing function: Functions.HttpHS2 ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: Failure Exception: OSError: [Errno 30] Read-only file system: '/home/site/wwwroot/pickle/HillData.pckl'

The function works locally (on Windows), but the directory 'pickle' has been marked as read-only in the cloud (on Linux).

I can use the Explorer in Visual Studio Code to look at the directory and select "Reveal in File Explorer". There, I can choose 'Properties' in the context menu and see that the attribute 'Read-only' is set, and I can clear that, but it reappears immediately. When I navigate up one level, to the name of the function, I have the same behavior.

Some more background: The function is Python code that I have been working on on my old desktop PC, and I have reached the point where it needs more RAM. The existing code saves all of its data in a file (in pickle format). It reads the file, uses the data, adds some data, and saves the file. That means that it is convenient for me to use a subdirectory of the same name as the original code. I use Azure Storage Explorer to upload the current version of the data file to an Azure file share, then use the StoreFileClient to copy it to the 'pickle' subdirectory, the run the original Python code, then copy the data file back to the Azure file share, from where I can download it.

If there is some reason why the whole Azure Functions directory must be read-only on Linux, I could modify my original code to read/write directly on the Azure file share. If there is some way to set the 'pickle' directory to not be read-only, for example in host.json or somewhere else, that would be more convenient, because the original Python code would still run locally as well.

This post mentions setting FUNCTION_APP_EDIT_MODE in the portal, but I didn't find it there.
https://stackoverflow.com/questions/53630773/how-to-disable-read-only-mode-in-azure-function-app

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,890 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Thomas Ligon (Office 365) 26 Reputation points
    2022-09-12T22:00:20.327+00:00

    Thanks! This looks very good, but I am not able to see if it is working, because I am getting Unexpected status code: 500.
    I made the change the way you suggested on the portal. Then I discovered that this is also possible in Visual Studio Code. Here it still looks like all files are read-only, but I don't see whether I am still getting the error.

    240273-screenshot-2022-09-12-235709.jpg


  2. Thomas Ligon (Office 365) 26 Reputation points
    2022-09-15T08:36:17.057+00:00

    If I understand correctly, this setting is not enabled.
    On the portal, under Home / Function App / <name of function> / Configuration / Application Settings
    I found a number of settings, including FUNCTION_APP_EDIT_MODE, which is set to readwrite. I didn't find WEBSITE_RUN_FROM_PACKAGE, so I assume it is not set.
    I didn't find this kind of setting using VS Code, but I might not be looking in the right place.
    As a test, I ran the application locally, and then tested in the cloud, and the result was Unexpected status code: 500. I don't see anything else in the output or terminal window.
    In VS Code, I found Resources / <name> / Function App / <name> / Logs / Connect to Log Stream / Error_ Error "SyntaxError: Unexpected token ' in JSON at position 0" occurred while parsing the response body - '/Home/LogFiles' not found..
    On the portal, I tried enabling Log Stream, but didn't see anything new. Do I need to use Log Analytics?

    0 comments No comments

  3. Thomas Ligon (Office 365) 26 Reputation points
    2022-09-25T18:51:14.397+00:00

    I have a solution.
    This post
    https://stackoverflow.com/questions/63318567/azure-function-exception-oserror-errno-30-read-only-file-system
    says that, on Linux, only the /tmp directory is writable. So, I changed my code so that I no longer use '/home/site/wwwroot/pickle/HillData.pckl', but put pickle under /tmp.

    temp_dir = tempfile.gettempdir()  
    pickle_dir = os.path.join(temp_dir, 'pickle')  
    if not os.path.exists(pickle_dir):  
        os.mkdir(pickle_dir)  
    

    Locally (on Windows), that gives me pickle_dir = C:\Users\thoma\AppData\Local\Temp\pickle.

    and it looks good.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.