Wordpress-android: Duplicate media on upload after retry

Created on 19 Nov 2020  路  2Comments  路  Source: wordpress-mobile/WordPress-Android

Expected behavior

Retrying upload for a previously upload failed image should not result in duplicate images in the media library.

Actual behavior

If you upload more than one images at once and upload fails for an image, then on retrying to upload makes duplicate copies in the media library.

(Tested on a self-hosted site. Might also be reproducible on a simple WP site.)

Steps to reproduce the behavior

  1. Launch app
  2. Open a draft post in the Gutenberg Editor
  3. Select image block
  4. Select more than one images for upload
  5. Enable airplane mode, wait for ~1 min and then disable it while images are uploading so that images upload fails for at least one of the image (I also re-surfaced the app from background once)
  6. Click retry on the failed image
  7. Wait for the upload to complete
  8. Go to media library and notice duplicate copy of the failed image

Attempt 1: https://cloudup.com/izjkk0AITDc (Duplicate media on timestamp 1:14)

Attempt 2: https://cloudup.com/iydwecO-FxC (Duplicate media on timestamp 1:53)

Tested on [Pixel3 API 27], WPAndroid [16.2-rc-1]
Media [Type] Bug

All 2 comments

This is probably not related, but I thought I'd better drop a comment just to be sure. When we were dealing with posts being duplicated after retry, we came to a conclusion that it cannot be prevented without making changes to the API.

If the app sends a POST request and goes offline, the server will still process the request. However, the app will never receive a response so it assumes the request failed. Retry will send the same request again - however, since the post doesn't exist on the server yet, it doesn't have remote ID so it's treated by the server as a different post => duplicated post gets created.

I think it'll probably not be related to this issue, since images/files upload takes a while and the device would need to go offline in the exact right moment (the last byte was sent but the server didn't send a response yet).

Thanks @malinajirka !

If the app sends a POST request and goes offline, the server will still process the request. However, the app will never receive a response so it assumes the request failed. Retry will send the same request again

This is exactly what is happening in this case. This is how I verified:

  1. Create draft post (POST_ID = 0).
  2. Select several images for upload.
  3. Wait for few secs while images are uploading, then enable airplane mode.
  4. Notice in the desktop browser that one or more of the images get uploaded in the selected site -> media section (response not received by the app as it is in the offline mode).
  5. Disable airplane mode.
  6. Wait till we know upload status for all the images (images uploaded in step 4 included in the failed upload count).
  7. Retry upload (request included images uploaded in the step 4).
  8. Wait till all images are uploaded.
  9. Go to site's media section and notice that images that were uploaded in the step 4 are duplicated.

I could see duplicate images issue even for a post with id.

duplicate images

duplicate images for post with id

we came to a conclusion that it cannot be prevented without making changes to the API.

Looks like same conclusion applies in this case.

Was this page helpful?
0 / 5 - 0 ratings