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

reset() hold at onCancel #552

Open
TillJohanndeiter opened this issue Mar 1, 2025 · 4 comments
Open

reset() hold at onCancel #552

TillJohanndeiter opened this issue Mar 1, 2025 · 4 comments

Comments

@TillJohanndeiter
Copy link

TillJohanndeiter commented Mar 1, 2025

If i call

Repository().reset()

then the method is not finished. It seems to hold.

After debugging the code i figured out that it stuck in this line in onCancel of the StreamController

    final controller = StreamController<List<TModel>>(
      onCancel: () async {
        await channel.unsubscribe();
        // At this line it seems to stuck
        await supabaseRealtimeSubscriptions[TModel]?[eventType]?[query]?.close();
        supabaseRealtimeSubscriptions[TModel]?[eventType]?.remove(query);

        if (supabaseRealtimeSubscriptions[TModel]?[eventType]?.isEmpty ?? false) {
          supabaseRealtimeSubscriptions[TModel]?.remove(eventType);
        }

        if (supabaseRealtimeSubscriptions[TModel]?.isEmpty ?? false) {
          supabaseRealtimeSubscriptions.remove(TModel);
        }
      },
    );

In my project i use often a Riverpod StreamProvider e.g.:


final trainingRecordProvider = StreamProvider<List<TrainingRecord>>(
    (ref) => Repository().subscribeToRealtime<TrainingRecord>());

If you don't have an idea why, then i will setup a repo and try to reproduce the problem.

Thanks as always!

@TillJohanndeiter TillJohanndeiter changed the title Repository().reset() stuck at supabaseRealtimeSubscriptions[TModel]?[eventType]?[query]?.close() reset() stuck at onCancel Mar 1, 2025
@TillJohanndeiter TillJohanndeiter changed the title reset() stuck at onCancel reset() hold at onCancel Mar 1, 2025
@tshedor
Copy link
Collaborator

tshedor commented Mar 1, 2025

@TillJohanndeiter thanks for digging into the stack and finding the hanging line. I have no immediate idea of why that line itself would hang. When you debug with All Exceptions enabled, do you get any additional stack trace?

Otherwise, a repro example would be very helpful.

@TillJohanndeiter
Copy link
Author

@TillJohanndeiter thanks for digging into the stack and finding the hanging line. I have no immediate idea of why that line itself would hang. When you debug with All Exceptions enabled, do you get any additional stack trace?

Otherwise, a repro example would be very helpful.

Thanks for the quick response.

What do you mean with All Exceptions?

I will try to setup a repro example and will notice you.

@tshedor
Copy link
Collaborator

tshedor commented Mar 1, 2025

@TillJohanndeiter when you're using Flutter's debugger - either in the IDE or in the devtools instance that can be opened from flutter run - you can enable breakpoints on all exceptions to help further debug your code

@TillJohanndeiter
Copy link
Author

@TillJohanndeiter when you're using Flutter's debugger - either in the IDE or in the devtools instance that can be opened from flutter run - you can enable breakpoints on all exceptions to help further debug your code

Here is the repro example.

I altered your example_supabase and created a pr to you can see the difference a little bit more easier. I run brick mostly on web an linux. So i added some lines of code

On the web version i get this error:

SqfliteFfiException(error, Null check operator used on a null value}) DatabaseException(Null check operator used on a null value) sql 'ROLLBACK' {details: {database: {path: brick_offline_queue.sqlite, id: 2, readOnly: false, singleInstance: true}}}
    at Object.throw_ [as throw] (errors.dart:307:3)
    at Object.responseToResultOrThrow (method_call.dart:125:9)
    at database_factory_web.dart:91:30
    at async_patch.dart:622:19
    at async_patch.dart:647:23
    at async_patch.dart:593:31
    at _RootZone.runUnary (zone.dart:1849:54)
    at async._FutureListener.thenAwait.handleValue (future_impl.dart:208:18)
    at handleValueCallback (future_impl.dart:932:44)
    at _Future._propagateToListeners (future_impl.dart:961:13)
    at [_completeWithValue] (future_impl.dart:712:5)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:792:7)
    at Object._microtaskLoop (schedule_microtask.dart:40:11)
    at _startMicrotaskLoop (schedule_microtask.dart:49:5)
    at async_patch.dart:186:7

On linux it just stuck.

For the web version you have to run

dart run sqflite_common_ffi_web:setup

first

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

No branches or pull requests

2 participants