lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.13k stars 1.3k forks source link

Sharp with avajs exists with code -1073741819 #3476

Closed LCD344 closed 1 year ago

LCD344 commented 1 year ago

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 3.29 GB / 15.79 GB
  Binaries:
    Node: 17.0.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    sharp: ^0.31.2 => 0.31.2

What are the steps to reproduce?

I am using an express app where sharp handles photo uploads, the app itself works, but when I run it through a test (using Avajs - https://github.com/avajs/ava) it gives me the following error code

Process finished with exit code -1073741819 (0xC0000005)

While still running the test itself, but then I can't run more than one test at time.

Downgrading sharp to version 0.29.3 resolves the issue btw.

What is the expected behaviour?

The same, but not crashing the test when it works

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

This is my controller

import fs from 'fs';
import path from 'path';
import sharp from 'sharp';
import mkdirp from 'mkdirp';
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async generate(req, res) {
        const filePath = path.join(__dirname, `../../../public/images/${req.params.filename}`);
        if (!fs.existsSync(filePath)) {
            return res.status(404).json({
                error: 'Not Found'
            })
        }

        const thumbnailsDir = path.join(__dirname, '../../../public/thumbnails/');
        mkdirp.sync(thumbnailsDir);
        const thumbnailPath = path.join(thumbnailsDir, req.params.filename);
        await sharp(filePath).resize(200, 200, {
            withoutEnlargement: true,
            fit: 'outside'
        }).jpeg({progressive: true}).toFile(thumbnailPath);
        sharp.cache(false);
        return res.status(200).set('Cache-Control', 'public, max-age=31536000').sendFile(thumbnailPath);
    }

the following is the test code

import test from 'ava';
import app from '../../../app.js';
import request from 'supertest';
import path from 'path';
import fs from 'fs';

import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const src = path.resolve(__dirname, '../../demo.jpg');

test.serial('It returns thumbnails when the image is in the images directory', async t => {
    const imagePath = path.resolve(__dirname, '../../../public/images/demo.jpg');
    const thumbnailPath = path.resolve(__dirname, '../../../public/thumbnails/demo.jpg');

    fs.copyFileSync(src, imagePath);
    const response = await request(app).get('/api/thumbnails/demo.jpg');

    t.is(response.status, 200);
    t.true(response.body instanceof Buffer);
    fs.unlinkSync(imagePath);
    fs.unlinkSync(thumbnailPath);
});

If there is any idea what might be causing this, I would love to be using the latest version of sharp :)

lovell commented 1 year ago

Does using the ava --no-worker-threads flag help? (see #3164)

Node: 17.0.1

Node.js 17 reached EOL earlier this year and I recommend you upgrade.

LCD344 commented 1 year ago

@lovell - amazing! it works, I also updated node for good measure :)