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

Fix Socket.IO connection timeout #236

Merged
merged 9 commits into from
Feb 16, 2024
Merged

Conversation

Xmader
Copy link
Member

@Xmader Xmader commented Feb 2, 2024

This PR fixes the following issues:

  • In XMLHttpRequest, previously we throw a DOMException(InvalidAccessError) when trying to access the xhr.withCredentials getter/setter. However in socket.io-client, it tries to set xhr.withCredentials but cannot catch the exception, thus breaks the connection.

  • In our clearTimeout API, previously we expects the timeoutId argument is stored as an int32 value internally (JS numbers are always float64 values in JS context but mostly they are optimized internally). However in practice, JS number is not always optimized to an int32 value even though it's integral.
    In socket.io, old timers for the connection timeout don't get cancelled properly because the timeoutId seen as invalid, so the connection is closed prematurely.

  • xhr.responseType can be one of "" | "arraybuffer" | "blob" | "document" | "json" | "text". We implemented "text" and "arraybuffer", but "json" is missing, which socket.io also requires.
    "blob" or "document" are still TODOs because there's no point outside of browser environment.


This PR would close #232.

… is always a `JS::Value` of type `JSVAL_TYPE_INT32`
…g `xhr.withCredentials`

Socket.IO would die in the middle between `xhr.open` and `xhr.send`
@philippedistributive
Copy link
Collaborator

philippedistributive commented Feb 2, 2024

Please add a description with a reference to the issue this PR closes

Please add your posts regarding the issue from the python-monkey slack to the issue ticket so we have a clear reference and full activity log

Please document why the fixes other than commit a001cca are needed as this was not discussed in the slack chat or in the issue ticket

Also do we need to add a few tests at least no ensure no future regression?

@Xmader
Copy link
Member Author

Xmader commented Feb 6, 2024

Also do we need to add a few tests at least no ensure no future regression?

Would add standardized tests for XMLHttpRequest spec compliance in later PRs.

@philippedistributive
Copy link
Collaborator

philippedistributive commented Feb 6, 2024

Let's add that as a TODO new issue

-> DONE #239

@philippedistributive
Copy link
Collaborator

@Xmader please see how I documented the ticket for next time around

@philippedistributive
Copy link
Collaborator

philippedistributive commented Feb 13, 2024

Let's add the code so that the TODO tests described on line 40 and 41 of test_event_loop.py pass to this PR.

See also https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#non-number_delay_values_are_silently_coerced_into_numbers

for reference

Let's indeed make sure to have a full suite of tests for setTimeout/clearTimeOut while we're at it

@Xmader
Copy link
Member Author

Xmader commented Feb 16, 2024

Let's add the code so that the TODO tests described on line 40 and 41 of test_event_loop.py pass to this PR.

FYI They were implemented in

delayMs = Number(delayMs) || 0; // ensure the `delayMs` is a `number`, explicitly do type coercion
if (delayMs < 0)
delayMs = 0; // as spec-ed

OK then we just needed to clean up the TODOs :-)

@philippedistributive
Copy link
Collaborator

philippedistributive commented Feb 16, 2024

Final question: why couldn't we use the XMLHttpRequest from dcp-xhr.js in dcp instead of coming up with our own?

@Xmader
Copy link
Member Author

Xmader commented Feb 16, 2024

why couldn't we use the XMLHttpRequest from dcp-xhr.js in dcp

@philippedistributive Are you talking about https://gitlab.com/Distributed-Compute-Protocol/dcp/-/blob/develop/src/common/dcp-xhr.js?
It requires an external nodejs-only package xmlhttprequest-ssl, and only "patches" the XMLHttpRequest API the package provides.

coming up with our own

SpiderMonkey engine itself doesn't provide any network abilities. We need to implement the XMLHttpRequest API as well as all the network requesting stuff from ground up.

You can read https://github.com/Distributive-Network/PythonMonkey/blob/b1c3b6b/python/pythonmonkey/builtin_modules/XMLHttpRequest-internal.py

@Xmader Xmader merged commit 59b2fad into main Feb 16, 2024
24 checks passed
@Xmader Xmader deleted the Xmader/fix/socketio-connection-timeout branch February 16, 2024 18:23
@philippedistributive
Copy link
Collaborator

Thanks it was a bit of a superficial, non-researched little inquiry indeed

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

Successfully merging this pull request may close these issues.

segmentation fault after 60 seconds when trying to load socket.io
2 participants