nodeca / probe-image-size

Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO.
MIT License
977 stars 77 forks source link

Probe hanging without any error #58

Closed itsameandrea closed 3 years ago

itsameandrea commented 3 years ago

Hi there,

I have a function that is used to upload images to S3

async function uploadToBucket(options={}) {
  Sentry.addBreadcrumb({category: 'async'})

  const {bucket, stream: body, file, extension, mimetype} = options
  const filename = filenameHandler(file, extension)

  const m = meter()
  const s3Stream = new stream.PassThrough()
  const dimensionStream = new stream.PassThrough()
  body
    .pipe(m)
    .pipe(s3Stream)

  body.pipe(dimensionStream)

  const {width, height} = await probe(dimensionStream)

  const s3Upload = await s3.upload({
    Bucket: bucket,
    Key: filename,
    Body: body,
    ContentType: mimetype,
  })
    .promise()
    .then(res => {
      return {
        filename,
        mimetype,
        size: m.bytes,
        width,
        height
      }
    })
    .catch(error => {
      logger.error(`S3 Failed: ${error}`)
    })

  return s3Upload
}

This has been working well with basically anything we've thrown at it. Except for this one image that wouldn't get uploaded. After some debugging I saw that the line where the upload to S3 is actually done would never be reached. Commenting out const {width, height} = await probe(dimensionStream) would make the upload work.

I tried wrapping probe in a try/catch block but to avail as no error is thrown. Probe just seems to be hanging. Any idea of what may be happening?

FYI this is the image that is creating this issue air-pollution

puzrin commented 3 years ago
node ./support/dump.js https://user-images.githubusercontent.com/4171627/119978058-748a2e80-bfb9-11eb-85e2-0e4b337ac276.jpg
https://user-images.githubusercontent.com/4171627/119978058-748a2e80-bfb9-11eb-85e2-0e4b337ac276.jpg: {
  width: 1200,
  height: 627,
  type: 'jpg',
  mime: 'image/jpeg',
  wUnits: 'px',
  hUnits: 'px',
  orientation: 1,
  length: 1007537,
  url: 'https://user-images.githubusercontent.com/4171627/119978058-748a2e80-bfb9-11eb-85e2-0e4b337ac276.jpg'
}

Can not reproduce.

puzrin commented 3 years ago

Closing as not reproducible / stale.

If you have more info - feel free to add anytime to reopen.