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

Memory leak on subscription #241

Open
abramenko95 opened this issue Nov 9, 2021 · 6 comments
Open

Memory leak on subscription #241

abramenko95 opened this issue Nov 9, 2021 · 6 comments

Comments

@abramenko95
Copy link

abramenko95 commented Nov 9, 2021

I am trying to use Oboe.js to subscription, receive and parse server data. I have problem with growing string inside function handleProgress() in file oboe-browser.js. In an hour and a half, the string grows from 1.4Mb to 150Mb. In a day, application (tab in browser) crashed. I am trying to use oboe.drop(), but it didn't work for me. I attach example of code and snapshots of memory samplings.

let subscription = oboe({
    url: 'SOME URL',
    cached: false,
  })
  .start(() => {
    // SOME COMMENTED CODE
  })
  .node('!.*', (status) => {
    // SOME COMMENTED CODE
    return oboe.drop();
  }).on('fail', function (error) {
    // SOME COMMENTED CODE
    return oboe.drop();
  });

snapshot2
spanshot1
Somebody know how fix this problem?

@Aigeec
Copy link
Collaborator

Aigeec commented Nov 9, 2021

What broswer and browser version is this? There can be weird behaviour in certain browsers where the responseText from the xhr requests is the entire response rather than the newly received part.

What is the use case here, site sits there consuming streamed data forever?

@abramenko95
Copy link
Author

What broswer and browser version is this? There can be weird behaviour in certain browsers where the responseText from the xhr requests is the entire response rather than the newly received part.

What is the use case here, site sits there consuming streamed data forever?

Browser Google Chrome 95.0.4638.69. Site consume actual receive streaming data (data from last response). I tried remove all operations with this data to avoid links from another variables for correct garbage collection, but it doesn't fix my problem. The memory used increases even when I use a subscription without handlers.

@Aigeec
Copy link
Collaborator

Aigeec commented Nov 13, 2021

So from what I can see doing some quick testing with xhr.responseText on chrome 95.0.4638.69 it seems it continues to grow over time. There is a stackoverflow post about it here https://stackoverflow.com/questions/21951175/comet-xmlhttprequest-responsetext-grows-endlessly.

function handleProgress () {
    if (String(xhr.status)[0] === '2') {
      var textSoFar = xhr.responseText
      var newText = (' ' + textSoFar.substr(numberOfCharsAlreadyGivenToCallback)).substr(1)

      /* Raise the event for new text.

       On older browsers, the new text is the whole response.
       On newer/better ones, the fragment part that we got since
       last progress. */

      if (newText) {
        emitStreamData(newText)
      }

      numberOfCharsAlreadyGivenToCallback = len(textSoFar)
    }
  }

So if xhr.responseText was huge, then it would be assigned to textSoFar which might explain the memory usage. will keep looking into it.

image

So if you could check your heap snaptshot and just check the path for those strings, I believe you'll see that it's all in the xhr object.

@Aigeec
Copy link
Collaborator

Aigeec commented Nov 13, 2021

What broswer and browser version is this? There can be weird behaviour in certain browsers where the responseText from the xhr requests is the entire response rather than the newly received part.
What is the use case here, site sits there consuming streamed data forever?

Browser Google Chrome 95.0.4638.69. Site consume actual receive streaming data (data from last response). I tried remove all operations with this data to avoid links from another variables for correct garbage collection, but it doesn't fix my problem. The memory used increases even when I use a subscription without handlers.

What version of Oboe are you using?

@nikkov
Copy link

nikkov commented Dec 13, 2021

What version of Oboe are you using?

2.1.4
As it seems to me the problem is described in this issue:
grpc-ecosystem/grpc-gateway#1783
and we are also use grpc-gateway with server-stream.
A possible solution is to use in oboe the fetch API, but the pull request is still not applied. #

@paulsmithkc
Copy link

@Aigeec From what I understand xhr.responseText is supposed to contain the entire content of the response, per the official specification.

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

No branches or pull requests

4 participants