TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.39k stars 10.34k forks source link

Ghost crashes when uploading a post image #12967

Closed lfuelling closed 3 years ago

lfuelling commented 3 years ago

Issue Summary

When trying to upload a post image in the editor, the POST to https://<hostname>/ghost/api/canary/admin/images/upload/ causes Ghost to crash resulting in a 502 from NGINX.

It really does a full restart, because hitting (spamming) refresh after the 502 results in the "updating our site" loading spinner and then (for a short time) the "starting up" laoding spinner.

To Reproduce

  1. Create a new post
  2. Write some text (potentially optional)
  3. Edit the post metadata
  4. Select a post image
  5. "Something went wrong" should appear
  6. (optional) spam refresh immideately after the upload fails
  7. "restarting" loader should appear

I expected the iimage to be uploaded. The file in question was well under the max filesize limit and I tried .jpg as well as .png.

Technical details:

lfuelling commented 3 years ago

I also tried running ghost directly with ghost run and following my steps to reproduce above*, resulting in the following output (including the newlines):

$ ghost run
The `ghost run` command is used by the configured Ghost process manager and for debugging. If you're not running this to debug something, you should run `ghost start` instead.
+ sudo node current/index.js
[2021-05-16 03:42:03] INFO Ghost is running in production...
[2021-05-16 03:42:03] INFO Your site is now available on https://<hostname>/
[2021-05-16 03:42:03] INFO Ctrl+C to shut down
[2021-05-16 03:42:03] INFO Ghost server started in 0.853s
[2021-05-16 03:42:03] INFO Database is in a ready state.
[2021-05-16 03:42:03] INFO Ghost database ready in 1.157s
[2021-05-16 03:42:06] INFO Ghost booted in 3.772s
[2021-05-16 03:42:06] INFO Migrating portal_plans setting from names to ids
[2021-05-16 03:42:06] INFO Could not find names in portal_plans setting, skipping migration
[2021-05-16 03:42:10] INFO "GET /ghost/" 200 48ms
[2021-05-16 03:42:10] INFO "GET /ghost/assets/vendor.min-1d0e4f046c2a602700d3667894edc116.js" 304 4ms
[2021-05-16 03:42:10] INFO "GET /ghost/assets/ghost.min-0b6e9b2a2da4a18970ef236c4770889a.js" 304 4ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/users/me/?include=roles" 200 71ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/site/" 200 6ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/config/" 200 29ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/settings/?group=site%2Ctheme%2Cprivate%2Cmembers%2Cportal%2Cnewsletter%2Cemail%2Camp%2Clabs%2Cslack%2Cunsplash%2Cviews%2Cfirstpromoter%2Coauth%2Ceditor" 200 65ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/notifications/" 200 60ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/posts/60a070d24cb7cc8f9a446829/" 200 134ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/members/?limit=1&filter=subscribed%3Atrue&include=labels%2CemailRecipients" 200 40ms
[2021-05-16 03:42:10] INFO "GET /ghost/api/canary/admin/themes/" 200 154ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/labels/?limit=all" 200 192ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/members/?limit=1&include=labels%2CemailRecipients" 200 203ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/members/?limit=1&filter=status%3Afree%2Cstatus%3A-free&include=labels%2CemailRecipients" 200 206ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/tags/?limit=all" 200 214ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/users/?limit=all&include=roles" 200 217ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/snippets/?limit=all" 200 146ms
[2021-05-16 03:42:11] INFO "GET /ghost/api/canary/admin/products/?limit=all" 200 24ms

*I just reloaded the editor instead of navigating to a new post.

acburdine commented 3 years ago

@lfuelling can you perhaps share the OS you're running Ghost on? I'm curious if this is at all related to https://github.com/docker-library/ghost/issues/256, where Sharp installed on certain node versions & os combinations results in segmentation faults during image uploads

lfuelling commented 3 years ago

I'm running Ghost on Debian 10, Linux 4.19.0-16-amd64.

It worked before upgrading to v4 but the issue you linked seems to be about non-amd64 systems.

I also tried installing sharp manually with npm and yarn, both without issues.

acburdine commented 3 years ago

@lfuelling yeah there was another issue that came up in the context of the one I linked earlier regarding non-amd64 systems, but the initial issue was related to people experiencing restarts on Alpine Linux amd64.

The issue that I found was that sharp seemed to think it installed correctly, but something under the hood wasn't linking correctly, resulting in segmentation faults occurring whenever Ghost attempted to handle image resizing with sharp.

ixbarbarbar commented 3 years ago

Since I upgraded to the 4.5 version I have the same issue to upload the image in the post. I'm in Debian 10 also.

Error in Nginx access.log :

x.x.x.x- - [21/May/2021:20:04:27 +0200] "POST /ghost/api/canary/admin/images/upload/ HTTP/1.1" 502 150 "https://www.xxxxxxxx.com/ghost/" "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"

Error in Nginx error.log

2021/05/21 20:04:27 [error] 30030#30030: *34083 upstream prematurely closed connection while reading response header from upstream, client: x.x.x.x, server: www.xxxxxxxxxxx.com, request: "POST /ghost/api/canary/admin/images/upload/ HTTP/1.1", upstream: "http://127.0.0.1:2368/ghost/api/canary/admin/images/upload/", host: "www.xxxxxxx.com", referrer: "https://www.xxxxxxx.com/ghost/"

Node version v14.17.0 (updated for the 4.5 version)

Force update after the installation of node with the command : ghost update 4.5.0 --force

Ghost doctor output : ✔ Checking system Node.js version - found v14.17.0 ✔ Checking logged in user ✔ Ensuring user is not logged in as ghost user ✔ Checking if logged in user is directory owner ✔ Checking current folder permissions System checks failed with message: 'Linux version is not Ubuntu 16, 18, or 20' Some features of Ghost-CLI may not work without additional configuration. For local installs we recommend usingghost install localinstead. Instance is currently running ℹ Validating config [skipped] ✔ Checking folder permissions ✔ Checking file permissions ✔ Checking content folder ownership ✔ Checking memory availability ✔ Checking binary dependencies ✔ Checking free space ✔ Checking systemd unit file ✔ Checking systemd node version - found v14.17.0

I found also this issue https://github.com/TryGhost/Ghost/issues/11129 I tried to add in my config the line "imageOptimization": { "resize": false }

After a restart of ghost I can upload the image but general error and don't save the post Request was rejected due to server error

On the nginx error 2021/05/21 22:43:29 [error] 33250#33250: *3128 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: x.x.x.x server: www.xxxxxxxx.com, request: "PUT /ghost/api/canary/admin/posts/60a540f1a4a3dd67d2cf1fe9/ HTTP/1.1", upstream: "http://127.0.0.1:2368/ghost/api/canary/admin/posts/60a540f1a4a3dd67d2cf1fe9/", host: "www.xxxxxxxx.com", referrer: "https://www.xxxxxxx.com/ghost/"

In the developer console I have this error Uncaught (in promise) DOMException: A network error occurred.

Thank you for the help

felipeparpinelli commented 3 years ago

Same problem here. When I try to upload images using S3 integration (connector hasn't been updated for a long time btw https://github.com/colinmeinke/ghost-storage-adapter-s3), the route /ghost/api/canary/admin/images/upload/ returns 404. To debug I used the connector with cloudinary and also saving local images and everything worked fine.

Pop!_OS 20.04 LTS Ghost v4.7.0

Screenshot from 2021-06-12 19-12-30

pascalandy commented 3 years ago

@felipeparpinelli node version ?

felipeparpinelli commented 3 years ago

@pascalandy using node v14.16.1 (nvm) on the local machine and happened using docker on AWS ECS too (FROM node:14.16.1-alpine).

pascalandy commented 3 years ago

They why. Use Debian or node12-alpine

felipeparpinelli commented 3 years ago

@pascalandy Sorry, my mistake. Now the problem was in my S3 specific setup. I was able to see through the tab network where the problem was. Now everything works fine here. Thanks!

ErisDS commented 3 years ago

I believe this was an issue with the sharp dependency which has since been resolved here:

https://github.com/lovell/sharp/commit/b69a54fc75a21e12caf80fc7d12c1693a8b4b45b

nolo14 commented 3 years ago

Anyone have a solution? I update to 4.11 still same issue. Image upload crash site :(

themaster567 commented 3 years ago

Same here, getting a crash when trying to upload any image. I am also running Debian 10.

lfuelling commented 3 years ago

@nolo14. @themaster567 you can make sure you have libvips-dev installed and you can run npm i -g sharp without errors.

I think there might be something else missing as well but you should be able to solve it by following the logged errors when installing sharp fails with something else than libvips.

themaster567 commented 3 years ago

@nolo14. @themaster567 you can make sure you have libvips-dev installed and you can run npm i -g sharp without errors.

I think there might be something else missing as well but you should be able to solve it by following the logged errors when installing sharp fails with something else than libvips.

I'm using the official docker image, so unfortunately I don't think this is related. In addition, the error logs contain zero useful information: https://pastebin.com/VkVLpVFW

EDIT: I've now made an issue in the proper location https://github.com/docker-library/ghost/issues/267#issue-988627499

zengrotrust commented 1 year ago

After ran root@43844e37bd46:/var/lib/ghost/versions/5.33.8/node_modules# rm -R sharp in the container console, I can finally upload images without crashing the web server.

"sharp is a high-performance image processing module for Node.js. This module assists with UGC management by offering an easy solution for reading, enhancing, and saving image files. sharp compresses images faster than most other Node.js modules, like ImageMagick, Jimp, or Squoosh, and produces high-quality results."

disgustipated commented 1 year ago

Thats just removing a node module, it doesnt work on 5.35 latest docker image. Well, it does stop the container from crashing but it also doesnt let you upload the image saying sharp isnt installed(because it was removed)

disgustipated commented 1 year ago

Thought it was just the docker based container install but then went ahead with the install in ubuntu also and got the same thing, the process crashes. in dev tools i get an err_conn_refused and then it starts returning 503s after the service crashes. this isnt even going through nginx either, straight to the local ip of my box.

must be my cpu on my server. setting the config option to disable image optimization worked, which i found here https://github.com/TryGhost/Ghost/issues/13986 it does still look related to sharp but removing the node module like @zengrotrust suggested will just break it adding this to the config makes it work for me "imageOptimization": { "resize": false }