Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Memory leak when runing compose in worker #17

Closed
mohsen1 opened this issue Sep 18, 2015 · 2 comments
Closed

Memory leak when runing compose in worker #17

mohsen1 opened this issue Sep 18, 2015 · 2 comments

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Sep 18, 2015

Here is what I've done to reproduce this bug:

1. Make an HTML file with following content:

<html>
  <head></head>
  <body>
    <script>
    var worker = new Worker('worker.js');

    worker.onmessage = function (message) {
      console.log(message.data);
    };

    fetch('file.yaml').then(function (resp) {
      resp.text().then(function(y) {
        worker.postMessage(y);
      });
    });
    </script>
  </body>
</html>

2. Next to index.html make a file an name it worker.js, it's exactly `yaml.js file with these lines added at the end:

onmessage = function (message) {
    postMessage(yaml.compose(message.data));
}

Which is basically adding a very simple Web Worker API to yaml-js. It also fixes the bug I reported in #16 by using this as global: var global = this;

3. Make another file and name it file.yaml. Content of this file can be found here: http://pastebin.com/c8AYYEGF

4. Run a static web server like http-server from this folder and open the browser. What I see is Chrome's "Aw! Snap!" message. When I profiled this, memory usage goes up and up until tab crashes

screen shot 2015-09-18 at 11 25 30 am

Firefox crashes also. Safari doesn't have the Fetch API so I can't test it but I'm pretty sure that would crash also.

Note that the same file and the same method is not having this issue when run in the main thread. So if you change the content of HTML file to following code, the error won't happen:

<html>
  <head></head>
  <body>
    <script src="https://rawgit.com/connec/yaml-js/master/yaml.js"></script>
    <script>
      fetch('file.yaml').then(function (resp) {
        resp.text().then(function(y) {
          console.log(yaml.compose(y));
        });
      });
    </script>
  </body>
</html>

You can also download all the files in one zip file from here: https://github.com/mohsen1/mohsen1.github.io/blob/b8d76793a1e81a6c35fe83de3fea322edac910db/assets/yaml.zip

This issue was originally raised in Swagger Editor:
swagger-api/swagger-editor#641
swagger-api/swagger-editor#658
swagger-api/swagger-editor#651

@mohsen1 mohsen1 changed the title Memory leak when run compose in worker Memory leak when runing compose in worker Sep 18, 2015
mohsen1 added a commit to swagger-api/swagger-editor that referenced this issue Sep 18, 2015
@connec
Copy link
Owner

connec commented Sep 20, 2015

Intriguing. I'll look into this as soon as I can.

@connec
Copy link
Owner

connec commented Sep 19, 2021

I'm going to close it since this repository is going to be archived. yaml-js has been unmaintained for some time, so it would be best to use something else.

@connec connec closed this as completed Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants