Azure App Service with [Linux-based Python 3.11]: OSError [Errno 28] No space left on device

Dcm 0 Reputation points
2025-04-23T10:36:37.1066667+00:00

All of a sudden, my Azure App Service (Linux-based, Python 3.11) started throwing the following error:

OSError: [Errno 28] No space left on device

This occurred at the following code location:

with open(log_file_path, 'a', encoding="utf-8") as file:

    file.write(log_entry)
```Note: The file already exists.

File path: `/home/site/wwwroot/
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,662 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bhargavi Naragani 3,075 Reputation points Microsoft External Staff
    2025-04-24T05:07:06.27+00:00

    Hi @Dcm ,

    Disk Space Limits Are Not Always About Used Size, your B3 plan gives you 10 GB of storage, but that space is shared across /home, /site, and /wwwroot and some of that space is also used by the underlying container OS, logs, temp files, and other runtime operations, not just your app code or logs. Even if your custom log folder shows only 152 MB used, the total space across the full /home may still be nearing its limit due to background processes, auto-generated logs, or framework cache.

    Even if the space is free, the number of inodes (file handles) might be exhausted. Every file and directory use an inode. In your case, 137 files may not seem like a lot, but it’s possible that some system-level processes or deployed packages create many small files elsewhere in /home.

    Azure App Service for Linux runs on containers. These containers sometimes impose stricter file or memory quotas, especially when you use persistent write operations and you have multiple concurrent writes then there’s a burst in app usage or logging frequency So, the error could be raised not due to lack of actual space, but due to container-level quotas being breached temporarily.

    Instead of continuously appending to a single file, use Python’s logging module with rotation handlers, this limits the log file size and number of files retained, preventing uncontrolled growth:

    from logging.handlers import RotatingFileHandler
    handler = RotatingFileHandler("log.txt", maxBytes=5*1024*1024, backupCount=5)
    

    RotatingFileHandler docs

    Rather than writing to the local file system, switch to Azure Monitor, Application Insights, or Log Analytics. These services are: Scalable, Managed, don’t use local disk and ideal for production workloads Azure Monitor Overview, Logging in Azure App Service

    If your app is growing and storage needs are increasing, consider scaling from B3 to Standard or higher. Higher tiers not only offer more disk space, but also better performance and diagnostic tools. App Service Plan Tiers

    If the answer is helpful, please click Accept Answer so that other people who faces similar issue may get benefitted from it.

    Let me know if you have any further Queries.

    1 person found this answer helpful.

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.