{"id":18558969,"url":"https://github.com/flyinprogrammer/uwsgi-flask-demo","last_synced_at":"2026-03-19T05:03:23.880Z","repository":{"id":126282330,"uuid":"458242731","full_name":"flyinprogrammer/uwsgi-flask-demo","owner":"flyinprogrammer","description":"Simple flask app with odd resource leak.","archived":false,"fork":false,"pushed_at":"2022-02-11T22:00:54.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-17T12:16:34.320Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flyinprogrammer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-11T15:35:04.000Z","updated_at":"2022-05-24T15:01:02.000Z","dependencies_parsed_at":"2023-06-16T03:00:10.842Z","dependency_job_id":null,"html_url":"https://github.com/flyinprogrammer/uwsgi-flask-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyinprogrammer%2Fuwsgi-flask-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyinprogrammer%2Fuwsgi-flask-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyinprogrammer%2Fuwsgi-flask-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyinprogrammer%2Fuwsgi-flask-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flyinprogrammer","download_url":"https://codeload.github.com/flyinprogrammer/uwsgi-flask-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254367335,"owners_count":22059491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:41:44.849Z","updated_at":"2025-10-25T18:34:44.421Z","avatar_url":"https://github.com/flyinprogrammer.png","language":"Makefile","readme":"# uWSGI Flask Demo\n\nSo this is a tiny app, we use uWSGI to set it up. Then I discovered [uwsgi#2406](https://github.com/unbit/uwsgi/issues/2406).\n\nIn theory you can easily reproduce this on an M1 laptop:\n\n\n1. Get yourself an M1 macbook/mini\n\n2. Get yourself some [Rancher Desktop](https://rancherdesktop.io/)\n\n3. Go get yourself some [buildx](https://docs.docker.com/buildx/working-with-buildx/)\n\n4. [optionally] Go get yourself some [wrk](https://github.com/wg/wrk)\n\n5. Run `make build-amd64`\n\n```shell\ngithub.com/flyinprogrammer/uwsgi-flask-demo via 🐍 v3.10.2 \n❯ make build-amd64                 \ndocker buildx build --load --platform linux/amd64 -t flyinprogrammer/uwsgi-flask-demo:amd64 .\n[+] Building 73.0s (10/10) FINISHED\n=\u003e [internal] load build definition from Dockerfile 0.0s\n=\u003e =\u003e transferring dockerfile: 176B 0.0s\n=\u003e [internal] load .dockerignore 0.0s\n=\u003e =\u003e transferring context: 3.84kB 0.0s\n=\u003e [internal] load metadata for docker.io/library/python:3.9 0.0s\n=\u003e [1/5] FROM docker.io/library/python:3.9 0.0s\n=\u003e [internal] load build context 0.0s\n=\u003e =\u003e transferring context: 5.77kB 0.0s\n=\u003e [2/5] WORKDIR /opt/app 0.0s\n=\u003e [3/5] COPY requirements.txt . 0.0s\n=\u003e [4/5] RUN pip install -r requirements.txt 72.8s\n=\u003e [5/5] COPY . . 0.0s\n=\u003e exporting to image 0.1s\n=\u003e =\u003e exporting layers 0.1s\n=\u003e =\u003e writing image sha256:cfdbd6edb293b1754343b8b660fe8d4c2244c1eeb5f2b5e363a72c92ead1a013 0.0s \n=\u003e =\u003e naming to docker.io/flyinprogrammer/uwsgi-flask-demo:amd64  0.0s \n\n```\n\n6. Run `make run-amd64`\n\n7. Watch the logs show socket 0 are full because something is sad.\n\n```shell\ngithub.com/flyinprogrammer/uwsgi-flask-demo via 🐍 v3.10.2 took 1m13s \n❯ make run-amd64\ndocker run --platform linux/amd64 --rm -it -p 8080:8080 -p 8081:8081 flyinprogrammer/uwsgi-flask-demo:amd64\n========== START UWSGI CONFIG ==========\n[uwsgi]\ndisable-logging = true\nhttp = :8080\nmodule = app:app\n\nstats-http = true\nstats-server = 0.0.0.0:8081\n\nmaster = true\nprocesses = 4\nsingle-interpreter = true\nenable-threads = true\nthreads = 2\nthunder-lock = true\n\nuid = nobody\n========== END UWSGI CONFIG ==========\n[uWSGI] getting INI configuration from ./uwsgi.ini\n*** Starting uWSGI 2.0.20 (64bit) on [Fri Feb 11 17:24:00 2022] ***\ncompiled with version: 10.2.1 20210110 on 11 February 2022 17:01:55\nos: Linux-5.10.93-0-virt #1-Alpine SMP Thu, 27 Jan 2022 09:34:38 +0000\nnodename: 69c8157b72b2\nmachine: x86_64\nclock source: unix\npcre jit disabled\ndetected number of CPU cores: 6\ncurrent working directory: /opt/app\ndetected binary path: /usr/local/bin/uwsgi\nsetuid() to 65534\nyour memory page size is 4096 bytes\ndetected max file descriptor number: 1048576\nlock engine: pthread robust mutexes\n!!! it looks like your kernel does not support pthread robust mutexes !!!\n!!! falling back to standard pthread mutexes !!!\nthunder lock: enabled\nuWSGI http bound on :8080 fd 4\nuwsgi socket 0 bound to TCP address 127.0.0.1:40447 (port auto-assigned) fd 3\nPython version: 3.9.10 (main, Feb  8 2022, 05:06:38)  [GCC 10.2.1 20210110]\nPython main interpreter initialized at 0x4000172cb0\npython threads support enabled\nyour server socket listen backlog is limited to 100 connections\nyour mercy for graceful operations on workers is 60 seconds\nmapped 416880 bytes (407 KB) for 8 cores\n*** Operational MODE: preforking+threaded ***\nWSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x4000172cb0 pid: 10 (default app)\nspawned uWSGI master process (pid: 10)\nspawned uWSGI worker 1 (pid: 17, cores: 2)\nspawned uWSGI worker 2 (pid: 19, cores: 2)\nspawned uWSGI worker 3 (pid: 21, cores: 2)\nspawned uWSGI worker 4 (pid: 22, cores: 2)\n*** Stats server enabled on 0.0.0.0:8081 fd: 18 ***\nspawned uWSGI http 1 (pid: 25)\nFri Feb 11 17:24:02 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nFri Feb 11 17:24:03 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nFri Feb 11 17:24:04 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nFri Feb 11 17:24:05 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nFri Feb 11 17:24:06 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\n^CSIGINT/SIGTERM received...killing workers...\ngateway \"uWSGI http 1\" has been buried (pid: 25)\nFri Feb 11 17:24:07 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nFri Feb 11 17:24:08 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\nworker 1 buried after 1 seconds\nworker 2 buried after 1 seconds\n[deadlock-detector] pid 21 was holding lock thunder (0x40045a5000)\nworker 3 buried after 1 seconds\nworker 4 buried after 1 seconds\ngoodbye to uWSGI.\nmake: *** [run-amd64] Error 130\n```\n\nThis is the sad:\n\n```text\nFri Feb 11 17:24:08 2022 - *** uWSGI listen queue of socket \"127.0.0.1:40447\" (fd: 3) full !!! (74256320/64) ***\n```\n\nWho is hurting our little socket?\n\n8. Watch this problem go away with:\n\n```shell\nmake build-arm64\nmake run-arm64\n```\n\n* Be confused and amazed anything in this world works.\n* Schedule time to have an exetentional crisis about \"What is a thread?\".\n\n9. Iterate on combinations of configurations because you're a monkey and curious.\nThen establish a crude pattern that the issue seems to be related to something about\nthe `master = true` and that the stats server requires `master = true` to spawn. Also\nno combination of `processes` and `threads` seemed to have any impact this.\n\n10. Get your hands on a _real_ x86 linux computer because life is spectacular these day.\nThen run a public version of this image, and notice the error only exists on top\nof the qemu emulation bits. :shrug:\n\n```shell\ndocker run --init --rm -it -p 8080:8080 -p 8081:8081 flyinprogrammer/uwsgi-flask-demo:amd64\n```\n\n11. Look for friends on The Internet to help because I am dumb and perhaps they have\nsome easy answers rather than loosing my life to figuring how to debug this with\ngdb or something. :shrug:\n\n\n# Notes\n\n## Docker Tags\n\nI know Docker and other CLI tools don't require architecture as part of the tags, it just\nseemed to make things easier when testing locally. It also seems impossible to inspect\narchitecture at runtime other than `docker top \u003cconainer name\u003e` and see `/usr/bin/qemu-x86_64`\nin front of all your processes :sparkles: magic :sparkles:.\n\n## wrk\n\nI optionally install and used wrk to figure out if maybe adding load would help or hurt things.\nSo far it seems like there's nothing to write home about other than, \"qemu is slow\" which\nis hilarious because \"qemu\" is actually the 8th Wonder in the world.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyinprogrammer%2Fuwsgi-flask-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflyinprogrammer%2Fuwsgi-flask-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyinprogrammer%2Fuwsgi-flask-demo/lists"}