Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathAccessException in cleanup.dart #1177

Closed
thePeras opened this issue Mar 1, 2024 · 1 comment · Fixed by #1194
Closed

PathAccessException in cleanup.dart #1177

thePeras opened this issue Mar 1, 2024 · 1 comment · Fixed by #1194
Assignees
Labels
bug Something isn't working

Comments

@thePeras
Copy link
Member

thePeras commented Mar 1, 2024

A high rated exception captured by sentry in IOS devices only.

PathAccessException: Deletion failed, path = '/var/mobile/Containers/Data/Application/6E634CF6-78CB-433A-B01B-314123214/Documents' (OS Error: Operation not permitted, errno = 1)

Proposed solution:

  • Use getApplicationSupportDirectory instead of getApplicationDocumentsDirectory. (or use getApplicationSupportDirectory for IOS and the other for android)
  • Delete the files individually
@thePeras thePeras added the bug Something isn't working label Mar 1, 2024
@github-project-automation github-project-automation bot moved this to 📋 Product Backlog in UNI Mar 1, 2024
@limwa
Copy link
Member

limwa commented Mar 4, 2024

Furthermore, in cleanup.dart, some race conditions might be causing other errors.

Future<void> cleanupStoredData(BuildContext context) async {
StateProviders.fromContext(context).invalidate();
final prefs = await SharedPreferences.getInstance();
final faculties = PreferencesController.getUserFaculties();
await prefs.clear();
unawaited(
Future.wait([
AppLecturesDatabase().deleteLectures(),
AppExamsDatabase().deleteExams(),
AppCoursesDatabase().deleteCourses(),
AppUserDataDatabase().deleteUserData(),
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
]),
);
final path = (await getApplicationDocumentsDirectory()).path;
final directory = Directory(path);
if (directory.existsSync()) {
directory.deleteSync(recursive: true);
}
}

The race conditions I've found are the following:

  1. In line 19, the providers are invalidated, which causes them to reload data from the remotes. However, in lines 25 through 36, the database tables are deleted. The data, therefore, might be stored a database table which is then deleted.
  2. In lines 25 through 36, the database tables are deleted, but these operations are unawaited. In lines 38 through 42, all files inside the documents folder are deleted, which includes the database files. Therefore, sqflite is trying to send a delete table command to a file that might not exist anymore. The database connections should be closed before the database files are removed.

@github-project-automation github-project-automation bot moved this from 📋 Product Backlog to ✅ Done in UNI Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants