pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.07k stars 1.41k forks source link

FileStorage persistence sometimes doesn't save data to disk. #3074

Closed Malauch closed 3 months ago

Malauch commented 3 months ago

Description

I noticed that some mutations sequence of persisted shared state (file storage) breaks saving to disk. What is interesting that it has to be sequence of fast and little slower mutations. After saving on edit become broken then it stay broken until some other saving trigger will save the file (for example willResignActiveNotification), then it restores save on edit.

Problem occurs on either simulator and device and debug and release mode.

During test sometimes saving was broken immediately after second edit. However most of the time, sequence of edits was necessary to cause the problem

Below is a sample project which illustrates the problem and also screen recording. On screen recording I also catch some weird behaviour when editing file on disk, which caused some weird data values to be "restored"

sample project: SharedStateNotSaved.zip screen recording: https://nextcloud.pomba.org.pl/s/5QiK77q7AKSF49C

Checklist

Expected behavior

Shared state with file storage persistence should be reliably saved according to 1s eager throttle strategy.

Actual behavior

After some sequence of mutation saving is broken.

Steps to reproduce

  1. Run attached sample project.
  2. Tap increase button and then Read value from disk button to check if value was successfully saved.
  3. Tap Auto increase button, which fires a sequence of edits. After the edits and additional delay, value is read from disk.
  4. Both count values should be the same, but they are not.

The Composable Architecture version information

1.10.3

Destination operating system

17.14.1

Xcode version information

Version 15.3 (15E204a)

Swift Compiler version information

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
mbrandonw commented 3 months ago

@Malauch Good find! Thank you! We will get a release out very soon.