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

app crashes with Fatal Python error: ffi.from_handle() detected that the address passed points to garbage shortly after starting only on Windows since 20.4.0 #1587

Closed
PawelTroka opened this issue Apr 24, 2020 · 6 comments
Assignees
Labels
Loop: libuv Pertains to the libuv implementation Platform: Windows Pertaining only to Windows (tier 2) Type: Bug Identified as a bug; needs a code change to fix

Comments

@PawelTroka
Copy link

PawelTroka commented Apr 24, 2020

  • gevent version: 20.4.0
  • Python version: cPython 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 downloaded from python.org
  • Operating System: Microsoft Windows 10 Version 1903 (OS Build 18362.720)

Description:

Nothing fancy just running an app with Flask, gevent and gevent-websocket (all in their latest versions) and it crashes shortly after running. Sometimes it is nearly instantly, sometimes it takes even several seconds (no longer than a minute though) but it always does exit with error code. Strangely it only happens on Windows - on Linux Ubuntu (through docker) everything is all right. Everything worked OK back on gevent 1.5.0 but this warning (#1564) was written repeatedly.

Fatal Python error: 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

Thread 0x00004958 (most recent call first):
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_threading.py", line 60 in wait
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_threading.py", line 146 in get
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\threadpool.py", line 155 in run

Thread 0x00004ad8 (most recent call first):
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_threading.py", line 60 in wait
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_threading.py", line 146 in get
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\threadpool.py", line 155 in run

Current thread 0x0000549c (most recent call first):
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_ffi\loop.py", line 264 in python_stop
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\libuv\loop.py", line 498 in __run_queued_callbacks
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\libuv\loop.py", line 218 in _run_callbacks
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\_ffi\loop.py", line 300 in python_prepare_callback
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\libuv\loop.py", line 542 in run
  File "C:\Users\patr\AppData\Local\Programs\Python\Python38\lib\site-packages\gevent\hub.py", line 618 in run

Process finished with exit code -1073740791 (0xC0000409)
@PawelTroka PawelTroka changed the title app crashes with Fatal Python error: ffi.from_handle() detected that the address passed points to garbage shortly after starting only on Windows app crashes with Fatal Python error: ffi.from_handle() detected that the address passed points to garbage shortly after starting only on Windows since 20.4.0 Apr 24, 2020
@jamadden
Copy link
Member

Can you provide a short, self contained example that reliably crashes? Without being able to reproduce the problem it's very difficult to find and fix. It looks as if a watcher object is still active when it shouldn't be, but beyond that theres not much I can say.

Strangely it only happens on Windows - on Linux Ubuntu (through docker) everything is all right.

The default event loop is different on Windows and Linux. It would be interesting to know if using the libuv-cffi loop on Linux reproduces the crash.

@jamadden jamadden added Loop: libuv Pertains to the libuv implementation Platform: Windows Pertaining only to Windows (tier 2) Type: Bug Identified as a bug; needs a code change to fix labels Apr 24, 2020
@PawelTroka
Copy link
Author

@jamadden Ok, I can try to provide a short, self contained example but this is in proprietary application, so it can take me some time to properly extract that.

@jtc42
Copy link

jtc42 commented Apr 26, 2020

I'm facing the exact same issue. Gevent 20.04, Windows 10. Works fine on WSL2

@susoooon
Copy link

susoooon commented Apr 28, 2020

from gevent import monkey,pywsgi
monkey.patch_all(thread=False)
from flask import Flask,request
from flask import request, jsonify, json
app = Flask(__name__)

app.config['JSON_AS_ASCII'] = False


@app.route('/helloworld', methods=[ 'POST','GET'])
def hello():
    return "hello world"
if __name__ == '__main__':
    app.run(host="127.0.0.1",port=5000)

when i start flask and request,first time is ok,but second the error happend

PinkDraconian pushed a commit to PinkDraconian/Rocket-League-Private-Match-Brute-Forcer that referenced this issue Apr 30, 2020
Created the main file. Started testing. Due to bug had to switch over to a linux disto: gevent/gevent#1587
@int3l
Copy link

int3l commented May 3, 2020

Can confirm the same error on Windows 10 (1909) Latest with python 3.8.1 and gevent 20.5.0
As a workaround I should revert back to gevent 1.5.0 until this gets sorted.

Error output for reference:

Fatal Python error: 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

Thread 0x00000858 (most recent call first):
  File "Z:\Project\env\lib\site-packages\gevent\_threading.py", line 60 in wait
  File "Z:\Project\env\lib\site-packages\gevent\_threading.py", line 146 in get
  File "Z:\Project\env\lib\site-packages\gevent\threadpool.py", line 155 in run

Current thread 0x00002230 (most recent call first):
  File "Z:\Project\env\lib\site-packages\gevent\_ffi\loop.py", line 264 in python_stop
  File "Z:\Project\env\lib\site-packages\gevent\libuv\loop.py", line 498 in __run_queued_callbacks
  File "Z:\Project\env\lib\site-packages\gevent\libuv\loop.py", line 218 in _run_callbacks
  File "Z:\Project\env\lib\site-packages\gevent\_ffi\loop.py", line 300 in python_prepare_callback
  File "Z:\Project\env\lib\site-packages\gevent\libuv\loop.py", line 542 in run
  File "Z:\Project\env\lib\site-packages\gevent\hub.py", line 618 in run

@jamadden
Copy link
Member

jamadden commented May 6, 2020

Fixed in #1602, as best I can tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Loop: libuv Pertains to the libuv implementation Platform: Windows Pertaining only to Windows (tier 2) Type: Bug Identified as a bug; needs a code change to fix
Projects
None yet
Development

No branches or pull requests

5 participants