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

free(): invalid size #319

Closed
JeremyJames opened this issue Mar 25, 2024 · 34 comments
Closed

free(): invalid size #319

JeremyJames opened this issue Mar 25, 2024 · 34 comments
Assignees
Labels
bug Something isn't working sharp

Comments

@JeremyJames
Copy link

JeremyJames commented Mar 25, 2024

Hi,

Even after upgrading to 2.2.17, I'm still having this issue. Any idea?

Thanks a lot

Astro v4.5.9
AstroCompress v2.2.17

@bngmnn
Copy link

bngmnn commented Mar 25, 2024

Probably a duplicate of #316

@NikolaRHristov
Copy link
Member

@bngmnn This should've been fixed in v2.2.17

@JeremyJames Can you share some of the images you're trying to compress ? I would like to debug.

@JeremyJames
Copy link
Author

JeremyJames commented Mar 26, 2024

@bngmnn This should've been fixed in v2.2.17

@JeremyJames Can you share some of the images you're trying to compress ? I would like to debug.

You are right, the problem is with a specific image. If I remove it, it works well in v2.2.17.

Here's the culprit:

contact

Thanks for helping!

@NikolaRHristov
Copy link
Member

We found the culprit in lovell/sharp#3935 (comment). Cache will be disabled in v2.2.18

@NikolaRHristov
Copy link
Member

@JeremyJames Should be fixed in v2.2.19

@JeremyJames
Copy link
Author

Hello! I'm still getting the error.

I did the following steps:

  • Remove node_modules, .astro and dist folders
  • Run npm install, astro compress v 2.2.19 got installed
  • Run npm build 💥 free(): invalid size

Thanks for the help

@jurajkapsz
Copy link

jurajkapsz commented Mar 27, 2024

I've recently noticed this as well with v2.2.17 and v2.2.19: namely in astro dev mode, when an astro image component (eg Astro Picture) is part of the page content.
It looks like the "_image" image endpoint request causes the free(): invalid size crash.

astro build works fine.

@kristianfrost
Copy link

I second @jurajkapsz. I first tried removing all images. Then I tried commenting out the only element I have. And then I didn't get any errors — but no pictures 😆

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Mar 29, 2024

Can you share a bit of code on how you're running the <Image /> component and <Picture /> component maybe ? I'm trying all sorts of combinations but I can't get it to error. Maybe just an example and a few pictures will do.

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Mar 29, 2024

compress({
	Exclude: [(File: string) => File.indexOf("_image") !== -1],
});

And also does this 👆🏻 help ?

compress({
	Exclude: [
		(File: string) => {
			console.log(File);
			return false;
		},
	],
});

And what is the output of 👆🏻 ?

@enricogallesio
Copy link

I've recently noticed this as well with v2.2.17 and v2.2.19: namely in astro dev mode, when an astro image component (eg Astro Picture) is part of the page content. It looks like the "_image" image endpoint request causes the free(): invalid size crash.

astro build works fine.

This is confirmed in my case. I got the same issue

@NikolaRHristov
Copy link
Member

We don't compress in dev. CompressAstro hooks into the astro:build:done hook and only runs on build.

@jurajkapsz
Copy link

jurajkapsz commented Mar 30, 2024

We don't compress in dev. CompressAstro hooks into the astro:build:done hook and only runs on build.

Right, that's the interesting point, why it happens when CompressAstro is integrated. I'll make the tests you mentioned earlier.

In the meantime I've conditioned its integration in my astro config like so (probably not the proper way, but it works):

integrations: [
  import.meta.env.PROD &&
    (await import("astro-compress")).default({
      CSS: true,
      HTML: true,
      Image: true,
      JavaScript: true,
      SVG: true,
    }),
],

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Mar 30, 2024

So, there's a PR available withastro/astro#10616 in favor of disabling the sharp libvips image cache. Maybe it helps. I hope it gets merged and this gets resolved soon.

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 1, 2024

Can you try the latest astro-compress v2.2.21 and @playform/compress-astro v0.0.2 ? @JeremyJames @jurajkapsz @kristianfrost @enricogallesio

@jurajkapsz
Copy link

Can you try the latest astro-compress v2.2.21 and @playform/compress-astro v0.0.2

v2.2.21 didn't change anything. What is compress-astro v0.0.2?

@kristianfrost
Copy link

I get this error now:

npx astro add @playform/compress-astro
@playform/compress-astro doesn't appear to be an integration or an adapter. Find our official integrations at https://astro.build/integrations

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 2, 2024

@jurajkapsz it's a deprecated package. In the future only @playform/compress-astro will remain or the new package @playform/compress. They're all the same in terms of functionality just have different names. See: #324

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 2, 2024

@kristianfrost I see, it seems that the integration must have an astro-integration keyword in its package.json to be registered as an integration successfully by the Astro component. I removed it from the latest @playform/compress-astro v0.0.2 and astro-compress v2.2.21 as I didn't want to polute this page with https://astro.build/integrations/ two integrations that basically do the same thing internally.

You can add it to your package.json manually and it will still work. Just add:

	"dependencies": {
		"@playform/compress-astro": "0.0.2"		
	},

to your package.json and import compress() from @playform/compress-astro.

See: https://github.com/Playform/CompressAstro#install-dependencies-manually

Thank you for the tip! It will be re-added to the latest version.

@jurajkapsz
Copy link

jurajkapsz commented Apr 2, 2024

In reply to this comment:

compress({
	Exclude: [(File: string) => File.indexOf("_image") !== -1],
});

And also does this 👆🏻 help ?

No, it does not. Actually, to get the error, it seems, it is enough to just import the package into the astro config (I have import compress from "astro-compress";) without integrating anything.

In my package.json:

"dependencies": {
  "astro-compress": "^2.2.21",
}

compress({
	Exclude: [
		(File: string) => {
			console.log(File);
			return false;
		},
	],
});

And what is the output of 👆🏻 ?

Nothing, I get the usual:

free(): invalid size
Aborted (core dumped)

For me, this works fine (ie it does nothing on dev and compresses on build).

@NikolaRHristov
Copy link
Member

@jurajkapsz Hm, interesting..

@NikolaRHristov
Copy link
Member

It seems that importing two sharp instances causes this.

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 3, 2024

@jurajkapsz @enricogallesio @JeremyJames @bngmnn astro v4.5.15 just got released https://github.com/withastro/astro/blob/refs/heads/main/packages/astro/CHANGELOG.md#4515 with the PR merged - withastro/astro#10616.

Can you give that a try with the latest astro-compress v2.2.21 or @playform/compress-astro v0.0.2 ?

@jurajkapsz
Copy link

No change after latest updates, the issue remains.

@NikolaRHristov
Copy link
Member

Ok, there's one last resort I would like to try which might have been the culprit all this time https://github.com/Playform/Compress/blob/Current/Source/Function/Integration.ts#L203. Limiting / unlimiting the amount of memory used. I'll release a new version today with unlimited false see if that helps.

@JeremyJames
Copy link
Author

No change after latest updates, the issue remains.

Same here, still having the same error

@c3qo
Copy link

c3qo commented Apr 4, 2024

I used the astro-compress 2.2.21 and astro 4.5.15 on cloudflare, no luck. The error is different but may be same rootcause?

10:01:44.414 | munmap_chunk(): invalid pointer

Seems the astro-compress depends on sharp 0.33.3 and astro depends on sharp ^0.32.6, but the actual sharp installed into node_modules is 0.32.6.

As a workaround, overriding sharp version works. tested on cloudflare, the build passed.

  "overrides": {
    "sharp": "0.33.3"
  },

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 5, 2024

astro-compress v2.2.22 and @playform/compress v0.0.3 have been released with better error checking and unlimited sharp set to false in Source/Function/Integration.ts. Can you give that a try ? @JeremyJames @jurajkapsz @enricogallesio @kristianfrost

@NikolaRHristov
Copy link
Member

I used the astro-compress 2.2.21 and astro 4.5.15 on cloudflare, no luck. The error is different but may be same rootcause?

10:01:44.414 | munmap_chunk(): invalid pointer

Seems the astro-compress depends on sharp 0.33.3 and astro depends on sharp ^0.32.6, but the actual sharp installed into node_modules is 0.32.6.

As a workaround, overriding sharp version works. tested on cloudflare, the build passed.

  "overrides": {
    "sharp": "0.33.3"
  },

This will be fixed by #329. You can track that issue there @c3qo.

@jurajkapsz
Copy link

astro-compress v2.2.22 and @playform/compress v0.0.3 have been released with better error checking and unlimited sharp set to false in Source/Function/Integration.ts. Can you give that a try ?

Hi @NikolaRHristov , I switched to @playform/compress v0.0.3, and no change.

NB, there is a new warning showing up:

image

@NikolaRHristov
Copy link
Member

NikolaRHristov commented Apr 9, 2024

@jurajkapsz Yeah, I think it stems from the fact that sharp is imported at the main level in Source/Function/Integration.ts, which conflicts with the other sharp instance imported from astro.

If we import only where the sharp extension is used I think we can resolve this. A new version will be issued shortly.

As a hotfix, does the new method of importing Compress work for you btw ?

export default {
	integrations: [(await import("@playform/compress")).default()],
};

As for this:

NB, there is a new warning showing up:

image

I'll work on a solution.. Node really shouldn't be installing dependencies that are declared in devDependencies by default 😅

@jurajkapsz
Copy link

As a hotfix, does the new method of importing Compress work for you btw ?

export default {
	integrations: [(await import("@playform/compress")).default()],
};

I think I have it like that in my config as of now, so I don't think so.
But I use the workaround I mentioned before and I am perfectly fine with that.

Sporiff added a commit to adjust/dev-docs that referenced this issue Apr 22, 2024
@kristianfrost
Copy link

Does anyone have a fix for this issue? I'm still getting this:

21:01:32.925	 generating optimized images 
21:01:32.938	munmap_chunk(): invalid pointer
21:01:32.951	Aborted
21:01:32.962	Failed: Error while executing user command. Exited with error code: 134
21:01:32.972	Failed: build command exited with code: 1
21:01:34.192	Failed: error occurred while running build command

@NikolaRHristov
Copy link
Member

Should be fixed the latest astro-compress v2.2.23 and @playform/compress v0.0.4

@NikolaRHristov NikolaRHristov added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sharp
Development

No branches or pull requests

7 participants