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(gatsby-plugin-sharp): pass input buffer instead of readStream when processing image jobs #33685

Merged
merged 3 commits into from
Oct 27, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Oct 26, 2021

Description

With single readStream and multiple sharp pipelines there is opportunity for mishandling / not syncing things properly. In particular our setup was piping readStream too early (it should pipe it after all pipelines were created, but this ended up not being easy task due to way duotone option is handled, which essentially "consumes" pipeline build so far and building another pipeline on top of that).

I did check sharp internals, and it seems like there is no actual benefit of using streams over buffers, because sharp internally will "convert" stream to buffer anyway, before passing it to native land:
https://github.com/lovell/sharp/blob/319db21f29a3c838fe52aa0713a10837581e831c/lib/output.js#L1099-L1116
This is where JS pass things to C++ land, notice how it's not streaming, it just wait for readStream to finish and reader of data to push everything to buffer. Similarly C++ side of it only handle 2 cases - buffer or filepath (no mention of streams) - https://github.com/lovell/sharp/blob/319db21f29a3c838fe52aa0713a10837581e831c/src/common.cc#L77-L87

We do have still other cases of using read streams as input in plugin, but those are not problematic so far and they use single stream + single output model, so not converting them to buffers to focus on place with actual problem

Related Issues

Fixes #33557
[ch40306]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 26, 2021
@pieh pieh added topic: media Related to gatsby-plugin-image, or general image/media processing topics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Oct 26, 2021
@wardpeet wardpeet merged commit b800559 into master Oct 27, 2021
@wardpeet wardpeet deleted the fix/sharp-stream-hanging branch October 27, 2021 06:06
wardpeet pushed a commit that referenced this pull request Oct 27, 2021
…n processing image jobs (#33685)

(cherry picked from commit b800559)
wardpeet pushed a commit that referenced this pull request Oct 27, 2021
…n processing image jobs (#33685) (#33694)

Co-authored-by: Michal Piechowiak <[email protected]>
vladar pushed a commit that referenced this pull request Oct 27, 2021
…n processing image jobs (#33685)

(cherry picked from commit b800559)
vladar pushed a commit that referenced this pull request Oct 28, 2021
…n processing image jobs (#33685) (#33703)

(cherry picked from commit b800559)

Co-authored-by: Michal Piechowiak <[email protected]>
wardpeet pushed a commit to herecydev/gatsby that referenced this pull request Oct 29, 2021
axe312ger pushed a commit that referenced this pull request Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: media Related to gatsby-plugin-image, or general image/media processing topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gatsby build occasionally time out after "Caching JavaScript and CSS webpack compilation"
2 participants