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

exit with code -1073741819 (0xC0000005) #271

Open
hjdhnx opened this issue Mar 8, 2024 · 7 comments
Open

exit with code -1073741819 (0xC0000005) #271

hjdhnx opened this issue Mar 8, 2024 · 7 comments

Comments

@hjdhnx
Copy link

hjdhnx commented Mar 8, 2024

Issue type

Bug

How did you install PythonMonkey?

Installed from pip
https://nightly.pythonmonkey.io/pythonmonkey/

OS platform and distribution

windows11

Python version (python --version)

3.8.8 64bit

PythonMonkey version (pip show pythonmonkey)

0.3.1.dev83+b2be8c9

Bug Description

When I use PythonMonkey in interface services, such as FastAPI, as long as I load a JavaScript module and use it as a Python variable, when I call the method of this variable again, the entire interface backend service process will be forced to exit

from pythonmonkey import eval as js_eval, require as js_require
from pathlib import Path
drpy_file = Path(os.path.join(BASE_DIR, './t4/files/drpy3_libs/drpy3.min.js')).as_posix()
DRPY = js_require(drpy_file)
@router.get(api_url + '_test', summary="t")
def vod_test():
    # http://localhost:5707/api/v1/vod_test
    api_path = get_api_path('996影视.js')
    api_text = get_file_text(api_path)
    DRPY.init(api_text) # this line will be exited
    api_text += f'\nvar DRPY = {DRPY}'
    return Response(api_text, media_type='text/javascript; charset=utf-8')

look here

image

Standalone code to reproduce the issue

drpy.js

function init(text) {
    console.log('init:', text)
    return text
}
function home(text) {
    console.log('home:', text)
    return text
}
module.exports = {
    init,
    home,
}

drpy_run.py

import pythonmonkey as pm
from pythonmonkey import eval as js_eval, require as js_require

if __name__ == '__main__':
    DRPY = js_require('./drpy.js')  # it's ok
    print(DRPY)
    print(DRPY.init('hello'))
    print(DRPY.home('world'))

main.py

import pythonmonkey as pm
from pythonmonkey import eval as js_eval, require as js_require

from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    # print(pm.globalThis)
    DRPY = js_require('./drpy.js')  # exit with code -1073741819 (0xC0000005)
    # print(DRPY) # # exit with code -1073741819 (0xC0000005)
    # print(DRPY.init('hello')) # # exit with code -1073741819 (0xC0000005)
    # print(DRPY.home('world')) # # exit with code -1073741819 (0xC0000005)
    return {"pm_version": pm.__version__}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}


if __name__ == '__main__':
    import uvicorn

    uvicorn.run(
        app='main:app',
    )

drpy_run.py tests ok,but main.py tests error
when we view this http api, this bug happend
http://127.0.0.1:8000
@wesgarland @philippedistributive

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

@wesgarland
Copy link
Collaborator

I suspect PythonMonkey is segfaulting here, likely due to a GC root that isn't being persisted properly. What do you think, @caleb-distributive ?

@wesgarland
Copy link
Collaborator

wesgarland commented Mar 8, 2024

Access violation exceptions (0xc0000005= STATUS_ACCESS_VIOLATION) are generated by modern processors when a memory access caused by an instruction or program execution does not satisfy certain conditions defined by the processor architecture or memory management unit structures.

So this means probably that we tried to access a page which isn't mapped into the process address space.

The most likely address for that is NULL - we're probably de-referencing a NULL ptr the second time through.

@wesgarland
Copy link
Collaborator

I just noticed you are on Python 3.8, @caleb-distributive are there important things that don't work under 3.9 that could affect this user?

@philippedistributive philippedistributive self-assigned this Mar 11, 2024
@philippedistributive
Copy link
Collaborator

philippedistributive commented Mar 11, 2024

@hjdhnx please provide the most minimal possible example with all files needed to reproduce

@hjdhnx
Copy link
Author

hjdhnx commented Mar 12, 2024

Standalone code to reproduce the issue

see Standalone code to reproduce the issue

@wesgarland wesgarland moved this from Backlog to Ready To Do in PythonMonkey Kanban Board Mar 14, 2024
@philippedistributive philippedistributive removed their assignment Mar 15, 2024
@karenbatch1997 karenbatch1997 added this to the v1.0.0 milestone Mar 20, 2024
@philippedistributive
Copy link
Collaborator

philippedistributive commented Mar 21, 2024

@hjdhnx
on ubuntu I get
INFO: Started server process [345480]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
have you tried on linux? is this happening only on windows?

@philippedistributive philippedistributive modified the milestone: v1.0.0 Apr 4, 2024
@philippedistributive philippedistributive removed this from the v1.0.0 milestone May 16, 2024
@philippedistributive philippedistributive closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@github-project-automation github-project-automation bot moved this from Ready To Do to Done in PythonMonkey Kanban Board Jun 14, 2024
@github-project-automation github-project-automation bot moved this from Done to Backlog in PythonMonkey Kanban Board Jun 14, 2024
@slonopot
Copy link

I'm getting the same issue on Windows 11 with Python 3.12.2, pythonmonkey 0.7.1, 0.8.0, 0.8.1.dev3+5fc6ce0. Python just crashes when I try to import pythonmonkey or from pythonmonkey.lib import pmdb.

Is there anything I can do to help you debug this further?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

5 participants