Possible race condition with events
The code samples hint that you should first await startUpload to get the id, and then add the listeners. However, if for some reason the upload fails right away (e.g., file is too large), the error events will not fire for that specific ID (because the listener wasn't added yet). So in this case you will never know if the request failed or not.
Thanks for reporting this issue. Is this a problem with the code samples and there is a workaround, or it's an API issue? When the upload fails right away is an exception raised or does it fail silently?
Do you have any thoughts about a potential solution?
Hi Mark,
I've been doing a lot of updates to fit some requirements of my project under my own repo, I've mostly removed android support (not needed and just increases the apk size) and added some more functions to increase background execution time and query the remaining time.
For the race condition, my "fix" was just to add a delay to "_sendEventWithName" so it gives time for event listeners to be setup. It does not fail silently, it sends the error event normally, but there are no listeners yet because it happens in the same processing time as the startUpload call.
I'm sorry I didn't do a fork to make it easier to compare the changes, but I messed up with the code so much that it probably can't be merged anyways.
On Mon, Jul 15, 2019 at 12:02 PM Mark Allen [email protected] wrote:
Thanks for reporting this issue. Is this a problem with the code samples and there is a workaround, or it's an API issue? When the upload fails right away is an exception raised or does it fail silently?
Do you have any thoughts about a potential solution?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Vydia/react-native-background-upload/issues/152?email_source=notifications&email_token=ALU263CU3O5FLOXSZ5FLFM3P7SGQJA5CNFSM4IDB5222YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ57FZY#issuecomment-511439591, or mute the thread https://github.com/notifications/unsubscribe-auth/ALU263CLPH57UECURHXHU6TP7SGQJANCNFSM4IDB522Q .
No problem, I appreciate you taking the time to report these issues even tho it sounds like you have solved many of them in your fork.
delay to "_sendEventWithName" so it gives time for event listeners to be setup
Sounds like we just need a simple defer / setTimeout(..., 0) to allow the current call stack conclude before triggering the event. Should be easy enough — would accept a PR.
Has any progress been made on this? I ran into this issue when S3 immediately rejects a PUT when the header signatures do not match. The request fails silently. My (very loose) work around is to register the error listener first. That seems to catch most of the failures. I'm a JS guy, not a Java guy, but the fix doesn't seem difficult. If it's low priority on the project, maybe I take a stab at the PR.
EDIT: We were actually able to get around this by using a customUploadId and registering event listeners with null as the uploadId before we made the call to startUpload().