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

Refactor memory leak by setInterval code gatsby dev-ssr #36688

Closed
2 tasks done
simonjoom opened this issue Sep 25, 2022 · 2 comments
Closed
2 tasks done

Refactor memory leak by setInterval code gatsby dev-ssr #36688

simonjoom opened this issue Sep 25, 2022 · 2 comments
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@simonjoom
Copy link

simonjoom commented Sep 25, 2022

Preliminary Checks

Description

The code give me a problem to get a good result in the compilation of dev-ssr

Reproduction Link

https://github.com/noreproductionlinkprovided

Steps to Reproduce

  1. Need a big project with long webpack compilation to reproduce

...

Expected Result

Compilation ssr should to pass correctly

Actual Result

memory leak due to setInterval and too much pass attempt
In actual code setInterval can run again before the stream finish for a big render-page

Environment

Mac os
Last gatsby4

Config Flags

DEV_SSR:true

code problem:

let found = await searchFileForString(
page.componentChunkName,
htmlComponentRendererPath
)
if (!found) {
await new Promise<void>(resolve => {
let readAttempts = 0
const searchForStringInterval = setInterval(async () => {
readAttempts += 1
found = await searchFileForString(
page.componentChunkName,
htmlComponentRendererPath
)
if (found || (allowTimedFallback && readAttempts > 5)) {
clearInterval(searchForStringInterval)
resolve()
}
}, 300)
})
}
return found
}

My Resolution

increment readAttempts and remove setInterval

let found = await searchFileForString(page.componentChunkName, htmlComponentRendererPath);

  if (!found) { 
    const delay = (ms) => { new Promise(resolve => setTimeout(resolve, ms)) }
    const lookforit = async (readAttempts) => { 
      found = await searchFileForString(page.componentChunkName, htmlComponentRendererPath);
      if (found || allowTimedFallback && readAttempts > 50) {
        console.log("isfound", found)
        return found; 
      } else {
        console.log("notfound", found)
        await delay(300);
        return await lookforit(readAttempts+1)
      }
    } 

    const bool = await lookforit(0)
    return bool
}
@simonjoom simonjoom added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 25, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 25, 2022
@tyhopp
Copy link
Contributor

tyhopp commented Sep 28, 2022

Hi @simonjoom,

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

Thanks for using Gatsby! 💜

@tyhopp tyhopp added status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 28, 2022
@LekoArts
Copy link
Contributor

Hi!

Since we didn't receive an answer for 7 days or more about the ask of a reproduction I'm going to close this now, as we can't do much to help without a reproduction. If you are able to create a minimal reproduction for this then please do answer here or open a new issue with a reproduction. Thanks!

@LekoArts LekoArts closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants