Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost crashes when uploading a post image #12967

Closed
lfuelling opened this issue May 16, 2021 · 18 comments
Closed

Ghost crashes when uploading a post image #12967

lfuelling opened this issue May 16, 2021 · 18 comments

Comments

@lfuelling
Copy link

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:

  • Ghost Version: 4.5.0
  • Node Version: v14.17.0 (Nodesource)
  • Browser/OS: Firefox 88.0.1 and Brave 1.24.84 (Chromium 90)
  • Database: MySQL 15.1
@lfuelling
Copy link
Author

lfuelling commented May 16, 2021

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
Copy link
Member

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

@lfuelling
Copy link
Author

lfuelling commented May 16, 2021

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
Copy link
Member

@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
Copy link

ixbarbarbar commented May 21, 2021

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 #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

This comment has been minimized.

@pascalandy

This comment has been minimized.

@felipeparpinelli

This comment has been minimized.

@pascalandy

This comment has been minimized.

@felipeparpinelli

This comment has been minimized.

@ErisDS
Copy link
Member

ErisDS commented Jul 8, 2021

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

lovell/sharp@b69a54f

@nolo14
Copy link

nolo14 commented Aug 8, 2021

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

@themaster567
Copy link

themaster567 commented Sep 3, 2021

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

@lfuelling
Copy link
Author

@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
Copy link

themaster567 commented Sep 5, 2021

@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 docker-library/ghost#267 (comment)

@zengrotrust
Copy link

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
Copy link

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
Copy link

disgustipated commented Feb 19, 2023

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 #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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants