Compress icon indicating copy to clipboard operation
Compress copied to clipboard

free(): invalid size

Open JeremyJames opened this issue 11 months ago β€’ 32 comments

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

JeremyJames avatar Mar 25 '24 14:03 JeremyJames

Probably a duplicate of #316

bngmnn avatar Mar 25 '24 22:03 bngmnn

@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.

NikolaRHristov avatar Mar 25 '24 22:03 NikolaRHristov

@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!

JeremyJames avatar Mar 26 '24 08:03 JeremyJames

We found the culprit in https://github.com/lovell/sharp/issues/3935#issuecomment-1881866341. Cache will be disabled in v2.2.18

NikolaRHristov avatar Mar 26 '24 20:03 NikolaRHristov

@JeremyJames Should be fixed in v2.2.19

NikolaRHristov avatar Mar 26 '24 22:03 NikolaRHristov

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 :boom: free(): invalid size

Thanks for the help

JeremyJames avatar Mar 27 '24 08:03 JeremyJames

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.

jurajkapsz avatar Mar 27 '24 12:03 jurajkapsz

I second @jurajkapsz. I first tried removing all images. Then I tried commenting out the only <Picture /> element I have. And then I didn't get any errors β€” but no pictures πŸ˜†

kristianfrost avatar Mar 28 '24 16:03 kristianfrost

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 avatar Mar 29 '24 03:03 NikolaRHristov

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 πŸ‘†πŸ»β€€?

NikolaRHristov avatar Mar 29 '24 03:03 NikolaRHristov

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

enricogallesio avatar Mar 29 '24 16:03 enricogallesio

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

NikolaRHristov avatar Mar 30 '24 02:03 NikolaRHristov

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,
    }),
],

jurajkapsz avatar Mar 30 '24 08:03 jurajkapsz

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

NikolaRHristov avatar Mar 30 '24 11:03 NikolaRHristov

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

NikolaRHristov avatar Apr 01 '24 12:04 NikolaRHristov

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?

jurajkapsz avatar Apr 02 '24 11:04 jurajkapsz

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

kristianfrost avatar Apr 02 '24 11:04 kristianfrost

@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: https://github.com/Playform/CompressAstro/issues/324

NikolaRHristov avatar Apr 02 '24 11:04 NikolaRHristov

@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.

NikolaRHristov avatar Apr 02 '24 11:04 NikolaRHristov

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).

jurajkapsz avatar Apr 02 '24 12:04 jurajkapsz

@jurajkapsz Hm, interesting..

NikolaRHristov avatar Apr 02 '24 12:04 NikolaRHristov

It seems that importing two sharp instances causes this.

NikolaRHristov avatar Apr 02 '24 12:04 NikolaRHristov

@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 - https://github.com/withastro/astro/pull/10616.

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

NikolaRHristov avatar Apr 03 '24 17:04 NikolaRHristov

No change after latest updates, the issue remains.

jurajkapsz avatar Apr 04 '24 08:04 jurajkapsz

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.

NikolaRHristov avatar Apr 04 '24 08:04 NikolaRHristov

No change after latest updates, the issue remains.

Same here, still having the same error

JeremyJames avatar Apr 04 '24 09:04 JeremyJames

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"
  },

c3qo avatar Apr 04 '24 17:04 c3qo

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 avatar Apr 05 '24 13:04 NikolaRHristov

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 https://github.com/Playform/Compress/issues/329. You can track that issue there @c3qo.

NikolaRHristov avatar Apr 05 '24 13:04 NikolaRHristov

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

jurajkapsz avatar Apr 09 '24 18:04 jurajkapsz