#5892·casdoor

File session provider creates one file per cookieless API request and never cleans them up; fills disk/inodes (root cause of #5186)

Author: lavish-jangirCreated Sep 29, 2026Updated Sep 29, 2026

Summary

When redisEndpoint is empty (the default, and the all-in-one image), Casdoor uses beego's file session provider in ./tmp (main.go). Every request that arrives without a casdoor_session_id cookie creates a new session file. That includes service-to-service calls such as /api/batch-enforce using client-id/secret basic auth.

The files are removed only by the session GC. That GC runs once at startup and then every SessionGCMaxLifetime seconds, which defaults to 30 days (sessionCookieLifeTime). So in practice nothing is cleaned while the process is running, and file count grows linearly with API traffic until the disk or its inodes are exhausted. #5186 reported the same symptom (Kubernetes pods evicted for inode exhaustion) but was closed without a root cause. This is the root cause.

Version

Reproduced on casbin/casdoor:4.11.0. The same code exists in v1.8xx. We hit it on 1.892.0 running in a container with limited storage, where it required regular restarts. Once the disk was full, /api/batch-enforce started returning failures.

Reproduce

bash
# fresh casdoor:4.11.0 container, redisEndpoint empty
docker exec <casdoor> sh -c 'find tmp -type f | wc -l'        # N
for i in $(seq 300); do
  curl -s -o /dev/null -u "$CLIENT_ID:$CLIENT_SECRET" -X POST \
    "http://localhost:8000/api/batch-enforce?permissionId=built-in/permission-built-in" \
    -H 'Content-Type: application/json' -d '[["alice","/data","GET"]]'
done
docker exec <casdoor> sh -c 'find tmp -type f | wc -l'        # N + 300

The response status doesn't matter; even Unauthorized operation responses create a file. Each file is 60 bytes but takes a full filesystem block and an inode, so 300 calls took about 2 MB on disk.

With redisEndpoint=<host>:6379, the same 300 calls create 0 files. You get 301 Redis keys with a ~30-day TTL, and login and get-account still work. So Redis is a workaround, but the default deployment should not need it.

Suggested fixes (any of these would help)

  1. Don't create sessions for requests that don't need one. Skip session creation for API calls authenticated via Authorization header or client credentials, or create the session lazily, only when something is written to it.
  2. Decouple the GC interval from the session lifetime. For example, run the file-session GC hourly and delete files older than the lifetime, instead of running it once per 30 days.
  3. Document it. At minimum, say in the Docker and production docs that deployments without Redis accumulate session files in ./tmp, and recommend redisEndpoint for production.

Happy to open a PR for (1) or (2) if maintainers have a preference.