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: The process cannot access the file because it is being used by another process (Windows only) after breaking changes 9.0.0 #634

Open
stan-at-work opened this issue Oct 12, 2023 · 18 comments

Comments

@stan-at-work
Copy link

stan-at-work commented Oct 12, 2023

After I updated to version 9.0.0, I randomly got an error saying: 'The process cannot access the file because it is being used by another process.'

This only happened after I upgraded to version 9.0.0.

I investigated the issue and came to the conclusion that it comes down to this.

If a file wants to read the same key at the same time as another file is writing to the same key, then I get this error.

I fixed this by switching back to the previous stable version.

I suggest updating the readme to alert users of this breaking issue.

This error also corrupts the .dat file, so all your secure storage is corrupted and unusable.

The error:

flutter: Failed to decrypt data: Error 0x00000057: Failure on CryptUnprotectData()
Delete corrupt file: c:\users\USER\appdata\roaming\com.example\APPNAME\flutter_secure_storage.dat
flutter: error on refresh token: PathAccessException: Cannot delete file, path = 'c:\users\USER\appdata\roaming\com.example\APPNAME\flutter_secure_storage.dat' (OS Error: The process cannot access the file because it is being used by another process.
flutter: , errno = 32) - stack: #0   _checkForErrorResponse (dart:io/common.dart:55:9)
flutter: #1   _File._delete.<anonymous closure> (dart:io/file_impl.dart:315:7)
flutter: #2   _rootRunUnary (dart:async/zone.dart:1407:47)
flutter: #3   _CustomZone.runUnary (dart:async/zone.dart:1308:19)
flutter: <asynchronous suspension>
flutter: #4   DpapiJsonFileMapStorage.load
flutter_secure_storage_windows_ffi.dart:267
flutter: <asynchronous suspension>
flutter: #5   FlutterSecureStorageWindows.write
flutter_secure_storage_windows_ffi.dart:142
flutter: <asynchronous suspension>
flutter: #6   CoreAuthRepo.toggleLoginEnvironmentInSecureStorage
core_auth_repo.dart:127
flutter: <asynchronous suspension>
flutter: #7   CoreAuthBloc._tryAutoLogin
core_auth_bloc.dart:113
flutter: <asynchronous suspension>
flutter: #8   Bloc.on.<anonymous closure>.handleEvent
bloc.dart:229
flutter: <asynchronous suspension>
flutter:

Greetings. Please fix ;-) 👍

Code example provided by: @ReinRaus

Example

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

late final FlutterSecureStorage storage;

void main() {
  storage = const FlutterSecureStorage();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    var controller = ScrollController();
    controller.addListener(
      () => storage.write(key: "key", value: "${controller.offset}"),
    );

    return MaterialApp(
      title: 'Scroll quickly to see the bug.',
      home: Scaffold(
        body: ListView(
          controller: controller,
          children: [for (int i = 0; i < 100; i++) Text("$i")],
        ),
      ),
    );
  }
}
@ReinRaus
Copy link

Code example: #603 (comment)

@stan-at-work
Copy link
Author

@mogol

@KristijanMitrik
Copy link

Any updates on this issue @mogol ?

@stan-at-work
Copy link
Author

Any updates on this issue @mogol ?

You can use the previous version.

@xenSlayer
Copy link

any update on this issue?

stummk added a commit to we-kode/mml.administration-app that referenced this issue Jun 29, 2024
Secure storage has a known issues in Windows. It can not access path when used by another process juliansteenbakker/flutter_secure_storage#634
@xenSlayer
Copy link

@stan-at-work which previous version are you using to avoid this issue?

@stan-at-work
Copy link
Author

@stan-at-work which previous version are you using to avoid this issue?

I'm using flutter_secure_storage: ^8.1.0

@rodrigoreal
Copy link

any update on this issue?

@stan-at-work
Copy link
Author

Nope

@mikthemonster
Copy link

I have the same problem using flutter_secure_storage: ^9.2.2

@stan-at-work
Copy link
Author

stan-at-work commented Oct 9, 2024

I have the same problem using flutter_secure_storage: ^9.2.2

+1 i had the same error today after a long time of not having it again.

@stan-at-work
Copy link
Author

stan-at-work commented Oct 15, 2024

@mogol Any updates on this? the latest version and pub version had this critical bug.

@stan-at-work
Copy link
Author

@mogol ?

@juliansteenbakker
Copy link
Owner

Hi all, could you please check if this issue still exists with version v10.0.0-beta.1? Also, if this is still an issue, please provide a step by step guide on how to recreate this issue. Then i can look into it.

@durukan-iscan
Copy link

Hello @juliansteenbakker,

I have same Problem (only Windows) but i do not see "Windows OS Changes" in v10.0.0-beta.1 or v10.0.0-beta.2

@juliansteenbakker
Copy link
Owner

v10.0.0-beta.1 does have changes for windows, however they are more related to the win32 implementation in flutter, and not about this problem i can see. I am going to look into this issue.

@stan-at-work
Copy link
Author

v10.0.0-beta.1 does have changes for windows, however they are more related to the win32 implementation in flutter, and not about this problem i can see. I am going to look into this issue.

Hey,

I’m experiencing the same issue—it still persists.

There’s no specific pattern that I can recreate. It happens about once a day. I’ve noticed it tends to occur more often when in release mode.

I suspect it might be a race condition issue, possibly with locks not waiting for each other or something similar. But I’m not an expert. 😊

@nini22P
Copy link

nini22P commented Jan 26, 2025

Add multi storage file. It won't saved to a file at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants