toshok / toshok/echojs

XMLHttpRequest isn't rooted while in flight

Open
#24 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug easy GC
Dominant language
JavaScript
Stars
431
Forks
20
PR merge metrics
No merged PRs in 30d

Description

osx-test/hello-osx.js has this block:

            this.xmlhttp = new XMLHttpRequest();
            this.xmlhttp.onreadystatechange = () => {
        console.log ("readyState == " + this.xmlhttp.readyState);
        if (this.xmlhttp.readyState === 4) {
                    console.log ("woohoo!");
            console.log (this.xmlhttp.responseText);
        }
            };
        console.log (this.xmlhttp.onreadystatechange);
            this.xmlhttp.open('GET', 'http://www.google.com/', true);
            this.xmlhttp.send();

'xmlhttp' should be a local variable, but if you make it one we crash, since the .send() doesn't cause it to be rooted by the GC. The GC frees it and we crash when attempting to call the onreadystatechange callback.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the XMLHttpRequest example in osx-test/hello-osx.js and trace what happens from send() through the asynchronous onreadystatechange callback. Investigate how the runtime roots objects during an in-flight request. Done means the local XMLHttpRequest remains alive until the callback runs and the example no longer crashes after garbage collection.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.