cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Thread-safety issue on concurrent iOS' FileWriter.write()

Open fcamblor opened this issue 4 years ago • 0 comments
trafficstars

Bug Report

Problem

What is expected to happen?

When calling FileWriter.write() (with create:true flag) on same file concurrently leads to only one content (maybe the latest being written ?) to be stored into the file ultimately.

What does actually happen?

When calling FileWriter.write() (with create:true flag) on same file concurrently leads to both content being merged into the same file.

Information

I created a gist file allowing to test and reproduce the issue : https://gist.github.com/fcamblor/9d2552460766a2fe1e203fd45ddae449

The purpose is to concurrently call FileWriter.write(file, "a") and FileWriter.write(file, "b") then read file's content and check if its content's length is 1 (as expected).

If length is 2 (ab or ba) then it means that concurrent writes have been merged into the same file, which is unexpected.

When executing the snippet on Android, I always met the expectation. When executing the snippet on iOS, the expectation is not met quickly (either on 1st, 2nd or 3rd attempt in most of the cases).

Note : I stored file using cordova.file.dataDirectory

Command or Code

See this gist : https://gist.github.com/fcamblor/9d2552460766a2fe1e203fd45ddae449

Environment, Platform, Device

iPhone 11 Emulator running on iOS 13.2.2 and AppleWebKit/605.1.15

Version information

[email protected]

Installed platforms:
  android 8.1.0
  browser 6.0.0
  ios 5.1.1
cordova-android-firebase-gradle-release 4.0.0 "cordova-android-firebase-gradle-release"
cordova-background-geolocation 3.2.2 "BackgroundGeolocation"
cordova-plugin-androidx 2.0.0 "cordova-plugin-androidx"
cordova-plugin-androidx-adapter 1.1.1 "cordova-plugin-androidx-adapter"
cordova-plugin-background-fetch 5.6.0 "CDVBackgroundFetch"
cordova-plugin-cocoalumberjack 0.0.4 "CocoaLumberjack"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-exitapp-ios 1.0.0 "ExitApp"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-opener2 2.2.1 "File Opener2"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-firebasex 11.0.3-cli "Google Firebase Plugin"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-request-location-accuracy 2.3.0 "Request Location Accuracy"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova.plugins.diagnostic 6.0.2 "Diagnostic"
phonegap-plugin-barcodescanner 8.1.0 "BarcodeScanner"

Checklist

  • [X] I searched for existing GitHub issues

  • [ ] I updated all Cordova tooling to most recent version I tried to update [email protected] to [email protected] but was not able to make all my plugins work with this version. I should have tried to reproduce the error on a dedicated sample with only the file plugin installed on it, but I admit I didn't had the time to (yet).

  • [X] I included all the necessary information above

fcamblor avatar Jan 07 '21 23:01 fcamblor