apache / apache/cordova-plugin-file

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

Open
#450 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# 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

`cordova@9.0.0`

```> cordova platforms
Installed platforms:
android 8.1.0
browser 6.0.0
ios 5.1.1
```

```> cordova plugins
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 `cordova-ios@5.1.1` to `cordova@6.1.1` 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

Contributor guide

Open the contributing guide

Research direction

Start by running the linked reproduction gist with cordova-plugin-file on the reported iOS 13.2.2 environment, comparing concurrent FileWriter.write(file, "a") and FileWriter.write(file, "b") with the Android result. Trace the iOS implementation used by FileWriter.write() and verify the behavior after the change by checking that the final file content has length 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.