jimmynicol / image-resizer

On-the-fly image resizing using Node.js and GraphicsMagick. Heroku Ready!
MIT License
339 stars 104 forks source link

app crashes on jpg image #78

Closed shroukkhan closed 8 years ago

shroukkhan commented 8 years ago

Hi, The app works fine when I try to get a png image. however, whenever, it is a jpg image, it crashes with:

/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:32 throw err; ^ TypeError: Cannot read property 'ext' of null at Image.Object.defineProperty.set (/var/www/imageproxy/node_modules/image-resizer/src/image.js:194:34) at Response. (/var/www/imageproxy/node_modules/image-resizer/src/streams/sources/s3.js:65:28) at Request. (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:350:18) at Request.callListeners (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:100:18) at Request.emit (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:604:14) at Request.transition (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:21:12) at AcceptorStateMachine.runTo (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:14:12) at /var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request. (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:22:9) at Request. (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:606:12) at Request.callListeners (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:104:18) at Request.emit (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:604:14) at Request.transition (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:21:12) at AcceptorStateMachine.runTo (/var/www/imageproxy/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:14:12) [gulp] [nodemon] app crashed - waiting for file changes before starting...

Any idea what is going on ?

jimmynicol commented 8 years ago

I am not able to replicate this issue sorry. From the looks of the error it would appear that possibly your image is not correct, or can not be found?

shroukkhan commented 8 years ago

Hi,i forgot to update this. Yes, it was indeed an issue with the s3 provider. they did not manage the images well. all worked well after they fixed their end .

andrewcuthill commented 8 years ago

@shroukkhan

I have the same issue with some but not all requests.

Any chance you could elaborate on what the problem was for you and how you fixed it?

leesiongchan commented 8 years ago

@shroukkhan I have the same issue too.

shroukkhan commented 8 years ago

Hi @andrewcuthill @ahlee2326

I tracked down my issue to the case where it turned out it actually did NOT download the jpg image at all. In your case , make sure the jpg image is infact downloaded before passing it to resizer

leesiongchan commented 8 years ago

It seems it crashes when I access to root ( / ).

andrewcuthill commented 8 years ago

@shroukkhan I'm not sure what you mean by downloaded, but I tend to get a 503 error when I try and access the image directly without any modifiers.

shroukkhan commented 8 years ago

Please make sure the following:

  1. use separate aws sdk https://aws.amazon.com/sdk-for-node-js/ and make sure you can indeed download image from s3 bucket
  2. Once download is complete , make sure you can access the image from within the node app

if step1 and 2 are successful, carry on with the image resizer. In my case, i found the error in step1 ( as in image was not downloadable through s3 sdk ( some kind of corruption in the bucket ) ) and image rezier was trying to resize a non existing image.

fyi, i am not the writer of this module..i am merely a user :)

andrewcuthill commented 8 years ago

Thanks for replying @shroukkhan. What was the cause of the corruption?

I'm really struggling to get to the bottom of this - I've created a new bucket and migrated the content, created a new user in IAM, I can use aws s3api get-object with that user to get an image, yet image resizer will crash.

Sometimes if I restart the dyno, image resizer will successfully get the image.

shroukkhan commented 8 years ago

in my case, the corruption happened because we had migrated from one s3 compatible provider to another s3 compatible provider and they didnt really do their job very well. So i had to upload same images again into the new s3 bucket and then download+resize them through image resizer . Old existing images wont work.

bottom line of the issue is, it happens if you pass a non jpeg image ( or a corrupted image ) to image resizer and ask it to resize it.

andrewcuthill commented 8 years ago

@jimmynicol any ideas how I can try and attempt to debug this?

Here's an example - https://s3.amazonaws.com/ii-content/top_picks-image-compressor.jpg

Trying to access this via heroku fails

2015-12-03T03:58:50.939499+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/top_picks-image-compressor.jpg" host=polar-ridge-1391.herokuapp.com request_id=ff90cdff-8742-4f5d-b7c4-7922ef9d14f4 fwd="14.203.104.110" dyno=web.1 connect=1ms service=276ms status=503 bytes=0
2015-12-03T03:58:50.935893+00:00 app[web.1]: /app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:32
2015-12-03T03:58:50.935910+00:00 app[web.1]:           throw err;
2015-12-03T03:58:50.935912+00:00 app[web.1]:                 ^
2015-12-03T03:58:50.935913+00:00 app[web.1]: TypeError: Cannot read property 'ext' of null
2015-12-03T03:58:50.935914+00:00 app[web.1]:     at Image.Object.defineProperty.set (/app/node_modules/image-resizer/src/image.js:194:34)
2015-12-03T03:58:50.935915+00:00 app[web.1]:     at Response.<anonymous> (/app/node_modules/image-resizer/src/streams/sources/s3.js:65:28)
2015-12-03T03:58:50.935915+00:00 app[web.1]:     at Request.<anonymous> (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:350:18)
2015-12-03T03:58:50.935917+00:00 app[web.1]:     at Request.callListeners (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:100:18)
2015-12-03T03:58:50.935917+00:00 app[web.1]:     at Request.emit (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
2015-12-03T03:58:50.935918+00:00 app[web.1]:     at Request.emit (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:604:14)
2015-12-03T03:58:50.935919+00:00 app[web.1]:     at AcceptorStateMachine.runTo (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:14:12)
2015-12-03T03:58:50.935918+00:00 app[web.1]:     at Request.transition (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:21:12)
2015-12-03T03:58:50.935919+00:00 app[web.1]:     at /app/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:26:10
2015-12-03T03:58:50.935920+00:00 app[web.1]:     at Request.<anonymous> (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:22:9)
2015-12-03T03:58:50.935920+00:00 app[web.1]:     at Request.<anonymous> (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:606:12)
2015-12-03T03:58:50.935921+00:00 app[web.1]:     at Request.callListeners (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:104:18)
2015-12-03T03:58:50.935921+00:00 app[web.1]:     at Request.emit (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:604:14)
2015-12-03T03:58:50.935921+00:00 app[web.1]:     at Request.emit (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
2015-12-03T03:58:50.935922+00:00 app[web.1]:     at Request.transition (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/request.js:21:12)
2015-12-03T03:58:50.935922+00:00 app[web.1]:     at AcceptorStateMachine.runTo (/app/node_modules/image-resizer/node_modules/aws-sdk/lib/state_machine.js:14:12)
2015-12-03T03:58:51.534988+00:00 heroku[web.1]: State changed from up to crashed
2015-12-03T03:58:51.540338+00:00 heroku[web.1]: Process exited with status 1