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

Media: Setting featured image doesn't work due to memory error #8932

Closed
rachelmcr opened this Issue Mar 21, 2018 · 8 comments

Comments

Projects
None yet
6 participants
@rachelmcr
Member

rachelmcr commented Mar 21, 2018

Original report by @M1g4 in Automattic/wp-desktop#428

Scenario:

We're running a blog with a high number of pictures. Trying to attach a featured image to a post in the iOS-Wordpress-App causes an error. The reason for this error is the abnormal high amount of memory the process on the server needs while trying to load the media.

The Android-app works perfectly with the exact same blog and the same user.

Steps to reproduce

  1. Have a blog with a high amount of media
  2. Open iOS Wordpress app
  3. Start new post
  4. Go to options and try to set a featured image

What I expected

Thumbnails of my photos to pick one for upload

What happened instead

An error occurs, stating that a problem occured while trying to access my media. I don't know the exact english wording since I use the german app (see screenshot below).

App Version / OS version

Wordpress 9.5 // iOS 11.2.2

Context / Source

At 128 MB of maximum allowed memory, the server logs look like this while trying to attach a featured image using the iPhone app:
[21/Mar/2018:11:17:49 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 runtime=715792 php_memory=134217728
[21/Mar/2018:11:17:49 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 runtime=738591 php_memory=134217728
[21/Mar/2018:11:17:50 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 runtime=645105 php_memory=134217728

For comparison, here are the logs of the same process using the Android app:
[21/Mar/2018:11:18:47 +0100] "POST /xmlrpc.php HTTP/1.1" 200 791 runtime=1158547 php_memory=23068672
[21/Mar/2018:11:19:07 +0100] "POST /xmlrpc.php HTTP/1.1" 200 483 runtime=149115 php_memory=22020096
[21/Mar/2018:11:19:07 +0100] "POST /xmlrpc.php HTTP/1.1" 200 930 runtime=200736 php_memory=22020096

As you can see, the Android app causes the xmlrpc to use less memory. So we tried to increase the max allowed memory to 256 on our server. The result, this time including user agent data for your documents:

[21/Mar/2018:11:36:26 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 wp-iphone/9.5" runtime=944321 php_memory=268435456
[21/Mar/2018:11:36:26 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 wp-iphone/9.5" runtime=944745 php_memory=268435456
[21/Mar/2018:11:36:27 +0100] "POST /xmlrpc.php HTTP/1.1" 500 169 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 wp-iphone/9.5" runtime=872012 php_memory=268435456

As you can see, even 256 MB are not enough. This is a major problem for us, since the only solution without an update of the iOS app would mean archiving or deleting the main part of our images.

Screenshot

wordpress_fehler_app

@rachelmcr

This comment has been minimized.

Show comment
Hide comment
@rachelmcr

rachelmcr Mar 21, 2018

Member

Comment from @dmsnell on the original report:

The attempt to upload your media encountered a problem. Try again later.

That's an informal translation - only putting it here for the benefit of those who read this and have no idea what it says.

Member

rachelmcr commented Mar 21, 2018

Comment from @dmsnell on the original report:

The attempt to upload your media encountered a problem. Try again later.

That's an informal translation - only putting it here for the benefit of those who read this and have no idea what it says.

@M1g4

This comment has been minimized.

Show comment
Hide comment
@M1g4

M1g4 Mar 21, 2018

I can't edit my Issue since it was moved, but we've got additional information on the cause of the problem.

Take a look at how the wp.getMediaLibrary function works when using the iOS-app.

<?xmlversion="1.0"?>wp.getMediaLibrary0@.de********filtermedia_typeimage`

<?xml version="1.0"?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><i4>0</i4></value></param><param><value><string>***@***.de</string></value></param><param><value><string>**************</string></value></param></params></methodCall>

<?xml version="1.0"?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><i4>0</i4></value></param><param><value><string>***@***.de</string></value></param><param><value><string>**************</string></value></param><param><value><struct><member><name>filter</name><value><struct><member><name>media_type</name><value><string>image</string></value></member></struct></value></member></struct></value></param></params></methodCall>

and compare it to the function when using the Android app:

<?xml version='1.0' ?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><string>1</string></value></param><param><value><string>*******</string></value></param><param><value><string>**************</string></value></param><param><value><struct><member><name>number</name><value><i4>48</i4></value></member><member><name>mime_type</name><value><string>image/</string></value></member></struct></value></param></params></methodCall>

The number of images that gets returned is limited to 48 when using the Android app. This filter is not set in the iOS version of the app. We think that is what causes the error described above.

M1g4 commented Mar 21, 2018

I can't edit my Issue since it was moved, but we've got additional information on the cause of the problem.

Take a look at how the wp.getMediaLibrary function works when using the iOS-app.

<?xmlversion="1.0"?>wp.getMediaLibrary0@.de********filtermedia_typeimage`

<?xml version="1.0"?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><i4>0</i4></value></param><param><value><string>***@***.de</string></value></param><param><value><string>**************</string></value></param></params></methodCall>

<?xml version="1.0"?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><i4>0</i4></value></param><param><value><string>***@***.de</string></value></param><param><value><string>**************</string></value></param><param><value><struct><member><name>filter</name><value><struct><member><name>media_type</name><value><string>image</string></value></member></struct></value></member></struct></value></param></params></methodCall>

and compare it to the function when using the Android app:

<?xml version='1.0' ?><methodCall><methodName>wp.getMediaLibrary</methodName><params><param><value><string>1</string></value></param><param><value><string>*******</string></value></param><param><value><string>**************</string></value></param><param><value><struct><member><name>number</name><value><i4>48</i4></value></member><member><name>mime_type</name><value><string>image/</string></value></member></struct></value></param></params></methodCall>

The number of images that gets returned is limited to 48 when using the Android app. This filter is not set in the iOS version of the app. We think that is what causes the error described above.

@lingej

This comment has been minimized.

Show comment
Hide comment
@lingej

lingej Mar 21, 2018

i changed the default value of the wp-includes/class-wp-xmlrpc-server.php file in line 4288 from -1 to 128.

The app now works as desired

https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-xmlrpc-server.php#L4288

lingej commented Mar 21, 2018

i changed the default value of the wp-includes/class-wp-xmlrpc-server.php file in line 4288 from -1 to 128.

The app now works as desired

https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-xmlrpc-server.php#L4288

@elibud

This comment has been minimized.

Show comment
Hide comment
@elibud

elibud Mar 30, 2018

Contributor

Awesome, thanks for letting us know @lingej

Contributor

elibud commented Mar 30, 2018

Awesome, thanks for letting us know @lingej

@elibud elibud closed this Mar 30, 2018

@lingej

This comment has been minimized.

Show comment
Hide comment
@lingej

lingej Mar 31, 2018

Sorry but this issue should not be closed.

Changing the wordpress source is just a workaround and not a solution ( IMHO )

@elibud please reopen this issue.

lingej commented Mar 31, 2018

Sorry but this issue should not be closed.

Changing the wordpress source is just a workaround and not a solution ( IMHO )

@elibud please reopen this issue.

@elibud

This comment has been minimized.

Show comment
Hide comment
@elibud

elibud Apr 2, 2018

Contributor

Hi @lingej apologies about the misunderstanding, lets try to clarify a few issues here:

  • Uploading a post with a big number of images it not a problem on either platform, only setting the featured image doesn't work in iOS, right?
  • After updating wp-includes/class-wp-xmlrpc-server.php you are able to set the exact same image in the same post that was failing before in iOS?

Re reading the logs this is what I can see:

  • In Android the size of the image uploaded is 23MB
  • In iOS the size of the image uploaded is 134MB

That might explain why the server is accepting the featured image from Android but not from iOS. Can you try changing the iOS app settings and re-uploading an image? Me->App Settings->Max Image Upload Size.

Can you tell me more about the rationale behind the change on wp-includes/class-wp-xmlrpc-server.php?

Thank you

Contributor

elibud commented Apr 2, 2018

Hi @lingej apologies about the misunderstanding, lets try to clarify a few issues here:

  • Uploading a post with a big number of images it not a problem on either platform, only setting the featured image doesn't work in iOS, right?
  • After updating wp-includes/class-wp-xmlrpc-server.php you are able to set the exact same image in the same post that was failing before in iOS?

Re reading the logs this is what I can see:

  • In Android the size of the image uploaded is 23MB
  • In iOS the size of the image uploaded is 134MB

That might explain why the server is accepting the featured image from Android but not from iOS. Can you try changing the iOS app settings and re-uploading an image? Me->App Settings->Max Image Upload Size.

Can you tell me more about the rationale behind the change on wp-includes/class-wp-xmlrpc-server.php?

Thank you

@elibud elibud reopened this Apr 2, 2018

@elibud elibud self-assigned this Apr 2, 2018

@M1g4

This comment has been minimized.

Show comment
Hide comment
@M1g4

M1g4 Apr 3, 2018

Hi @elibud ,

I'll try to clarify the problem:
When setting the featured image, the iOS app tries to fetch all images that are currently available in the media database of the blog so that the user can choose one of the already available pictures instead of uploading a new one. This procedure starts a process on the server that tries to deliver all currently stored pictures in one turn. This process (on the server) needs way too much memory, which causes a PHP error, stops the process and causes an error in the app, which finally keeps the user from choosing any image (even the ones he stored on his mobile device). In the case of the iOS app, the size of the memory used by this process is 134 MB, which you can see in the logs. The logs don't show the size of the image we tried to upload, but the size of the process the app causes on the server. We tried to allow up to 256 MB of usable memory. The result: The process uses even more memory and crashes as well.

When setting the featured image on the Android app, the request contains a filter (in contrast to the IOS version) which limits the number of pictures loaded from the database to 48. Remember, the iOS app basically tells the server "show me every image ever stored in the database", which causes the process to use so much memory. The Android app utilizes this filter instead. This is why the process caused by the Android app uses only 23 MB, as you can see in the logs. Again, this is not related to the picture size, but shows the memory used by the process the apps starts on the server.

Just to sum things up:

  • The issue is not related to the process of uploading one picture (or any number of pictures) itself
  • The user can not even upload any picture because the app crashes due to the described problems
  • The issue is not related to the size of the image(s) chosen and is not affected by any changes in the Image Upload Size

The solution of the problem:
Just as you did in the Android version of the app, make the picture request of the iOS app contain a filter that limits the number of images to choose from (like the last 48 pictures, as the Android version does).

What we did was just a workaround that will be overwritten once we install the next wordpress update (and won't help any other users that face the same problem.)

Kind regards,
Sebastian

M1g4 commented Apr 3, 2018

Hi @elibud ,

I'll try to clarify the problem:
When setting the featured image, the iOS app tries to fetch all images that are currently available in the media database of the blog so that the user can choose one of the already available pictures instead of uploading a new one. This procedure starts a process on the server that tries to deliver all currently stored pictures in one turn. This process (on the server) needs way too much memory, which causes a PHP error, stops the process and causes an error in the app, which finally keeps the user from choosing any image (even the ones he stored on his mobile device). In the case of the iOS app, the size of the memory used by this process is 134 MB, which you can see in the logs. The logs don't show the size of the image we tried to upload, but the size of the process the app causes on the server. We tried to allow up to 256 MB of usable memory. The result: The process uses even more memory and crashes as well.

When setting the featured image on the Android app, the request contains a filter (in contrast to the IOS version) which limits the number of pictures loaded from the database to 48. Remember, the iOS app basically tells the server "show me every image ever stored in the database", which causes the process to use so much memory. The Android app utilizes this filter instead. This is why the process caused by the Android app uses only 23 MB, as you can see in the logs. Again, this is not related to the picture size, but shows the memory used by the process the apps starts on the server.

Just to sum things up:

  • The issue is not related to the process of uploading one picture (or any number of pictures) itself
  • The user can not even upload any picture because the app crashes due to the described problems
  • The issue is not related to the size of the image(s) chosen and is not affected by any changes in the Image Upload Size

The solution of the problem:
Just as you did in the Android version of the app, make the picture request of the iOS app contain a filter that limits the number of images to choose from (like the last 48 pictures, as the Android version does).

What we did was just a workaround that will be overwritten once we install the next wordpress update (and won't help any other users that face the same problem.)

Kind regards,
Sebastian

@elibud

This comment has been minimized.

Show comment
Hide comment
@elibud

elibud Apr 3, 2018

Contributor

Thank you Sebastian, totally understood now, we will take care of this.

Contributor

elibud commented Apr 3, 2018

Thank you Sebastian, totally understood now, we will take care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment