Skip to content
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

ffi.from_handle() detected that the address passed points to garbage #166

Open
Danangjoyoo opened this issue Feb 11, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@Danangjoyoo
Copy link

Describe the bug
My app crashes while doing load test

To Reproduce
Here is my code

from socketify import App, Request, Response

app = App()

async def hello(res: Response, req: Request):
    await res.get_json()
    res.end("Hello worldddddd!!!")

app.get("/", hello)
app.listen(8000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()

then I was tried to do load test with wrk

(venv) ○ wrk -t10 -c10 -d30s "http://127.0.0.1:8000/"
Running 30s test @ http://127.0.0.1:8000/
  10 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   438.10us  154.37us   4.37ms   86.68%
    Req/Sec     2.27k   504.77     2.74k    79.22%
  173675 requests in 30.08s, 19.71MB read
  Socket errors: connect 0, read 1251646, write 302755, timeout 0
Requests/sec:   5773.36
Transfer/sec:    670.93KB

then the error occurred, it said as below

(venv) ○ python socketify_app.py                     
Listening on port http://localhost:8000 now

Fatal Python error: b_from_handle: ffi.from_handle() detected that the address passed points to garbage. If it is really the result of ffi.new_handle(), then the Python object has already been garbage collected
Python runtime state: initialized

Current thread 0x00000001d99c9c40 (most recent call first):
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/cffi/api.py", line 544 in from_handle
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/socketify/socketify.py", line 1072 in uws_generic_on_data_handler
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/socketify/uv.py", line 89 in run_nowait
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/socketify/loop.py", line 95 in _keep_alive
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 80 in _run
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 1922 in _run_once
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 607 in run_forever
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/socketify/loop.py", line 125 in run
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/venv/lib/python3.11/site-packages/socketify/socketify.py", line 3379 in run
  File "/Users/agus.danangjoyo/dev/expython/test-rpc-4/socketify_app.py", line 11 in <module>

Extension modules: _cffi_backend (total: 1)
[1]    57479 abort      python socketify_app.py

Expected behavior
all is fine previously while doing simple load test, but this error happens when I add await res.get_json()

Desktop (please complete the following information):

  • OS: MacOS Sonoma 13

Additional context
I want to migrate my app from FastAPI to socketify, since the simple load test giving me about 10x times faster using socketify, but when I try to do simple body json read, my app crashes and I would be very happy for any resolutions!. thank you!

regards

@cirospaciari
Copy link
Owner

Probably #136 is also related with this

@cirospaciari cirospaciari added the bug Something isn't working label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants