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

Segmentation fault when calling quit() on a job event listener #387

Open
wiwichips opened this issue Jul 17, 2024 · 5 comments
Open

Segmentation fault when calling quit() on a job event listener #387

wiwichips opened this issue Jul 17, 2024 · 5 comments
Assignees
Milestone

Comments

@wiwichips
Copy link
Collaborator

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

Ubuntu 22.04.4 LTS x86_64

Python version (python --version)

3.10

PythonMonkey version (pip show pythonmonkey)

0.7.0

Bug Description

Not sure why in more detail, but when you call quit() on a job.on('accepted') listener, it seg faults every time!

Standalone code to reproduce the issue

#! /usr/bin/env python3

import pythonmonkey as pm
import asyncio

print(pm.__version__)

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

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


async def compute_for_it():
    pm.eval('''
    globalThis.myJob = dcp.compute.for(new Array(100), (x) => { progress(); return x + x })
    ''')
loop.run_until_complete(compute_for_it())

my_j = pm.eval("globalThis.myJob")

my_j.on('readystatechange', print)
my_j.on('accepted', lambda: quit())
my_j.on('result', print)


my_j.public.name = 'simple example'

async def exec_it():
    return await my_j.exec()
    
loop.run_until_complete(exec_it())

Relevant log output or backtrace

0.7.0
exec
init
preauth
deploying
listeners
compute-groups
uploading
deployed
Segmentation fault (core dumped)

Additional info if applicable

No response

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

No response

@philippedistributive
Copy link
Collaborator

stack looks like

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007ffff768597e in FuncType::getPyObject (cx=0x55555561b3f0, fval=...)
at /home/philippe/Sources/PythonMonkey/src/FuncType.cc:19
19 proxy->jsFunc->set(&fval.toObject());
(gdb) bt
#0 0x00007ffff768597e in FuncType::getPyObject (cx=0x55555561b3f0, fval=...)
at /home/philippe/Sources/PythonMonkey/src/FuncType.cc:19
#1 0x00007ffff76c605e in pyTypeFactory (cx=0x55555561b3f0, rval=...)
at /home/philippe/Sources/PythonMonkey/src/pyTypeFactory.cc:108
#2 0x00007ffff76b8ef4 in enqueueWithDelay (cx=0x55555561b3f0, argc=4, vp=0x7fffffffb998)
at /home/philippe/Sources/PythonMonkey/src/internalBinding/timers.cc:34
#3 0x000026506dd3de1b in ?? ()
#4 0x00001327f7a5d780 in ?? ()
#5 0x00007fffffffb970 in ?? ()
#6 0x0000000000000000 in ?? ()

@philippedistributive
Copy link
Collaborator

@wiwichips
This is due to quit not being async, (all other functions in the example are async) and is thus not supported without an async wrapper such as

async def async_quit():
quit()

my_j.on('accepted', lambda: async_quit())

@philippedistributive philippedistributive closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
@caleb-distributive
Copy link
Collaborator

Even if its unsupported, it should result in an exception, not a segmentation fault

@philippedistributive
Copy link
Collaborator

also works fine if not using lambda:
def non_async_quit():
quit()

my_j.on('accepted', non_async_quit())

@philippedistributive
Copy link
Collaborator

just made an incorrect pr closes comment

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

No branches or pull requests

3 participants