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
854 stars 40 forks source link

Segmentation Fault When running DCP Protocol Code #374

Closed wiwichips closed 4 months ago

wiwichips commented 4 months ago

Issue type

Bug

How did you install PythonMonkey?

Source

OS platform and distribution

Ubuntu 22.04.4 LTS

Python version (python --version)

3.10

PythonMonkey version (pip show pythonmonkey)

a7b92e896ff6b077f161b9ae79a9f5e55f4434b5

Bug Description

When I run ./ping-post-init.py on the Xmader/chore/moz-central branch as of commit a7b92e896ff6b077f161b9ae79a9f5e55f4434b5, I get a Seg Fault when I run Wes' python-launch-job ping-post-init.py script.

It seems to reliably seg fault each time I run.

Standalone code to reproduce the issue

#! /usr/bin/env python3
#
# @file         ping.py
#               Simple python program to connect to the job submit daemon, ping
#               it at the application layer, and close the connection.
# @author       Wes Garland, wes@distributive.network
# @date         March 2024
#

import pythonmonkey as pm
import asyncio
async def go():
    dcpConfig = pm.globalThis.dcpConfig
    Connection = pm.globalThis.dcp.protocol.Connection
    target = dcpConfig.scheduler.services.jobSubmit
    conn = pm.new(Connection)(target)

    conn.on("error",              lambda error:    print("! connection error:", error))
    conn.on("ready",              lambda:          print("! connection ready"))
    conn.on("session",            lambda unused:   print("! session established", conn.dcpsid))
    conn.on("end",                lambda:          print("! connection closing"))
    conn.on("close",              lambda *args:    print("! connection closed"))
    conn.on("disconnect",         lambda location: print("! transport layer disconnected from", location))
    conn.on("connect",            lambda location: print("! transport layer connected to", location))
    conn.on("connectionProgress", lambda obj:      print("! connection progress", obj))
# BUG under 5.3 !!!      conn.on("beforeSend",         lambda message:  print("! sending message", message)) 
    conn.on("beforeSend",         lambda message:  print("! sending", message.type))

    conn.state.on("change", lambda state, unused: print("! connection to", target.location.href, "now", state))
    print('connecting');
    await conn.connect()
    print('connected, sending keepalive');
    await conn.keepalive()
    print('received keepalive response; closing');
    conn.close()
    print('connection closed, exiting');

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

Relevant log output or backtrace

connecting
! connection to https://scheduler.distributed.computer/job-submit/ now connecting
! connection ready
! connection progress {'begin': 'socketio'}
! transport layer connected to {}
! sending request
connected, sending keepalive
! connection to https://scheduler.distributed.computer/job-submit/ now established
! session established jkgY57lE4gaw9jEUfVlpTDZEFf8J4cmZJUOSc6pP0N
! sending request
received keepalive response; closing
! connection to https://scheduler.distributed.computer/job-submit/ now closing
! connection closing
connection closed, exiting
! sending request
Task was destroyed but it is pending!
task: <Task pending name='Task-40' coro=<request() running at /home/will/.cache/pypoetry/virtualenvs/pythonmonkey-CupPGfSb-py3.10/lib/python3.10/site-packages/pythonmonkey/builtin_modules/XMLHttpRequest-internal.py:29> cb=[tuple.futureOnDoneCallback()]>
Segmentation fault (core dumped)

Additional info if applicable

dcp: e07c5c8b9e2a27d085e8d4a541b8f72153d822ec
dcp-client: 072cfedda17578ceb926317a218ff9d7b36babd7

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

Xmader/chore/moz-central

philippedistributive commented 4 months ago

No repro

wiwichips commented 4 months ago

Closing. Fixed in newest version of PythonMonkey