Distributive-Network / PythonMonkey

A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment.
https://pythonmonkey.io
Other
842 stars 38 forks source link

Segmentation Fault When Printing dcp['dcp-env'].global #379

Closed wiwichips closed 3 months ago

wiwichips commented 3 months ago

Issue type

Bug

How did you install PythonMonkey?

Source

OS platform and distribution

Ubuntu 22.04.4 LTS x86_64

Python version (python --version)

3.10

PythonMonkey version (pip show pythonmonkey)

0.6.1.dev220+80e90a4

Bug Description

I get a segmentation fault when I attempt to print dcp['dcp-env'].global

Standalone code to reproduce the issue

# run the following program - same file structure as Wes' `python-launch-job` repo

dcp_client = pm.require('dcp-client')
dcp_client['init']()

dcp_env = pm.eval('globalThis.dcp["dcp-env"]')

print(dcp_env['global'])

Relevant log output or backtrace

(pythonmonkey-py3.10) will@bestia:~/git/python-launch-job ➡ ASAN_OPTIONS=detect_leaks=0 LD_PRELOAD=$(gcc -print-file-name=libasan.so)  ./my-repro.py 
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1776855==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x74477226d9cc bp 0x7447691fa660 sp 0x7ffd2c0173d0 T0)
==1776855==The signal is caused by a READ memory access.
==1776855==Hint: address points to the zero page.
    #0 0x74477226d9cc in JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc(JSObjectProxy*) (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x299cc)
    #1 0x55d2b6bd96e6  (/usr/bin/python3.10+0x7d6e6)
    #2 0x744772264210 in DictType::getPyObject(JSContext*, JS::Handle<JS::Value>) (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x20210)
    #3 0x744772284683 in pyTypeFactory(JSContext*, JS::Handle<JS::Value>) (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x40683)
    #4 0x744772270431 in JSObjectProxyMethodDefinitions::JSObjectProxy_repr(JSObjectProxy*) (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x2c431)
    #5 0x55d2b6cc877a in PyObject_Repr (/usr/bin/python3.10+0x16c77a)
    #6 0x74477227043c in JSObjectProxyMethodDefinitions::JSObjectProxy_repr(JSObjectProxy*) (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x2c43c)
    #7 0x55d2b6ccc61c in PyObject_Str (/usr/bin/python3.10+0x17061c)
    #8 0x55d2b6d9685c in PyFile_WriteObject (/usr/bin/python3.10+0x23a85c)
    #9 0x55d2b6d95f01  (/usr/bin/python3.10+0x239f01)
    #10 0x55d2b6ca999a  (/usr/bin/python3.10+0x14d99a)
    #11 0x55d2b6c9f26c in _PyEval_EvalFrameDefault (/usr/bin/python3.10+0x14326c)
    #12 0x55d2b6c9b9c5  (/usr/bin/python3.10+0x13f9c5)
    #13 0x55d2b6d91255 in PyEval_EvalCode (/usr/bin/python3.10+0x235255)
    #14 0x55d2b6dbc107  (/usr/bin/python3.10+0x260107)
    #15 0x55d2b6db59ca  (/usr/bin/python3.10+0x2599ca)
    #16 0x55d2b6dbbe54  (/usr/bin/python3.10+0x25fe54)
    #17 0x55d2b6dbb337 in _PyRun_SimpleFileObject (/usr/bin/python3.10+0x25f337)
    #18 0x55d2b6dbaf82 in _PyRun_AnyFileObject (/usr/bin/python3.10+0x25ef82)
    #19 0x55d2b6dada5d in Py_RunMain (/usr/bin/python3.10+0x251a5d)
    #20 0x55d2b6d8402c in Py_BytesMain (/usr/bin/python3.10+0x22802c)
    #21 0x744772029d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #22 0x744772029e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #23 0x55d2b6d83f24 in _start (/usr/bin/python3.10+0x227f24)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/will/git/pythonmonkey/python/pythonmonkey/pythonmonkey.so+0x299cc) in JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc(JSObjectProxy*)
==1776855==ABORTING

Additional info if applicable

(pythonmonkey-py3.10) will@bestia:~/git/python-launch-job ➡ python3 -c "import pythonmonkey as pm; print(pm.__version__)"
0.6.1.dev220+80e90a4

(pythonmonkey-py3.10) will@bestia:~/git/python-launch-job ➡ npm ls
python-launch-job@1.0.0 /home/will/git/python-launch-job
└── dcp-client@4.4.6 -> ./../dcp-client

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

main

wiwichips commented 3 months ago

need to run npm i dcp-client@develop to use dcp-client with PythonMonkey

philippedistributive commented 3 months ago

get TypeError: cyclic object value if try to print it in JS code -> dcp_client/index.py See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value

philippedistributive commented 3 months ago

indeed trouble is in JSObjectProxy_repr

philippedistributive commented 3 months ago

trouble is while parsing dcpConfig such as the one at https://scheduler.distributed.computer/etc/dcp-config.js we balk at processing: "identity": Promise.resolve('0xC6Ff3Ada812725d3F63661E206D28356adF40eFC')

philippedistributive commented 3 months ago

printing out just globalThis is also a problem