Comments (7)
Hey @davidmartos96 !
Thanks for your message.
Indeed, I've done a minimal repo and tried to reproduce the error... and I cannot :)
The bug might be on my side.
I'll reopen if I find anything.
Cheers !
(sandbox repo: https://github.com/tpucci/electricsql_sandbox, unit test: https://github.com/tpucci/electricsql_sandbox/blob/main/test/dumb_test.dart)
from electric_dart.
@tpucci We were able to reproduce it, thank you for the example!
We have a PR on the Javascript Electric client with a proposed fix. If that gets accepted as a valid solution we will port it to the Dart client.
A temporary solution would be to add a delay right after your await electricClient.close()
to give it some time to end the snapshot in this race condition.
Something like await Future<void>.delayed(const Duration(milliseconds: 500))
I'd say would be more than enough in the meantime.
from electric_dart.
@tpucci Hello!
What version of electricsql
are you using?
When doing await electricClient.close()
, the code that periodically performs a snapshot of changes should be stopped.
Could you provide a simple unit test file (with setUp, tearDown) that reproduces this issue?
Feel free to post the full logs too, it might be easier to tell.
from electric_dart.
@tpucci For reference, the "delete local database" functionality in the Todos example does a "teardown" as follows. It's essentially what you are doing in your code snippet. It looks ok at first glance.
await electric.close();
await todosDb.close();
await deleteTodosDbFile();
from electric_dart.
Reopening because of new findings.
Here is a video of a strange behavior on my sandbox repo
(sandbox repo: https://github.com/tpucci/electricsql_sandbox, unit test: https://github.com/tpucci/electricsql_sandbox/blob/main/test/dumb_test.dart)
As you can see, inserting more data make the test fail.
Complete logs:
CouldNotRollBackException: Bad state: Tried to send Request (id = 50): RunTransactionAction(TransactionControl.rollback, 5) over isolate channel, but the connection was closed!.
For context: The transaction was rolled back because of Channel was closed before receiving a response, which was thrown here:
dart:async/future_impl.dart 20:44 _Completer.completeError
package:electricsql/src/drivers/drift/drift_adapter.dart 57:19 DriftAdapter.transaction.<fn>.<fn>
package:electricsql/src/drivers/drift/drift_adapter.dart 92:20 Transaction.query.<fn>
package:stack_trace/src/stack_zone_specification.dart 127:36 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 127:24 StackZoneSpecification._registerUnaryCallback.<fn>
dart:async/zone.dart 1407:47 _rootRunUnary
dart:async/zone.dart 1308:19 _CustomZone.runUnary
dart:async/future_impl.dart 180:22 _FutureListener.handleError
dart:async/future_impl.dart 850:47 Future._propagateToListeners.handleError
dart:async/future_impl.dart 871:13 Future._propagateToListeners
dart:async/future_impl.dart 651:5 Future._completeError
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
dart:async/future_impl.dart 972:17 _registerErrorHandler
dart:async/future_impl.dart 361:17 Future.catchError
package:electricsql/src/drivers/drift/drift_adapter.dart 90:8 Transaction.query
package:electricsql/src/satellite/process.dart 1073:12 SatelliteProcess.performSnapshot.<fn>
package:electricsql/src/drivers/drift/drift_adapter.dart 59:8 DriftAdapter.transaction.<fn>
package:drift/src/runtime/api/connection_user.dart 465:38 DatabaseConnectionUser.transaction.<fn>.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:drift/src/runtime/api/connection_user.dart 532:12 DatabaseConnectionUser._runConnectionZoned
package:drift/src/runtime/api/connection_user.dart 462:14 DatabaseConnectionUser.transaction.<fn>
package:drift/src/runtime/api/connection_user.dart 162:64 DatabaseConnectionUser.doWhenOpened.<fn>
package:stack_trace/src/stack_zone_specification.dart 127:36 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 127:24 StackZoneSpecification._registerUnaryCallback.<fn>
dart:async/zone.dart 1407:47 _rootRunUnary
dart:async/zone.dart 1308:19 _CustomZone.runUnary
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
dart:async/future_impl.dart 331:23 Future.then
package:drift/src/runtime/api/connection_user.dart 162:50 DatabaseConnectionUser.doWhenOpened
package:drift/src/runtime/api/connection_user.dart 458:27 DatabaseConnectionUser.transaction
package:electricsql/src/drivers/drift/drift_adapter.dart 55:15 DriftAdapter.transaction
package:electricsql/src/satellite/process.dart 1072:25 SatelliteProcess.performSnapshot
package:electricsql/src/satellite/process.dart 144:14 SatelliteProcess._mutexSnapshot.<fn>
package:synchronized/src/basic_lock.dart 31:24 BasicLock.synchronized
package:electricsql/src/satellite/process.dart 143:26 SatelliteProcess._mutexSnapshot
dart:core-patch/function_patch.dart 11:71 Function._apply
dart:core-patch/function_patch.dart 35:12 Function.apply
package:rate_limiter/src/debounce.dart 92:31 Debounce._invokeFunc
package:rate_limiter/src/debounce.dart 120:14 Debounce._trailingEdge
package:rate_limiter/src/debounce.dart 139:7 Debounce._timerExpired
package:rate_limiter/src/debounce.dart 96:60 Debounce._startTimer.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 114:48 StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1391:47 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1209:7 _CustomZone.runGuarded
dart:async/zone.dart 1249:23 _CustomZone.bindCallbackGuarded.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 114:48 StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1233:23 _CustomZone.bindCallback.<fn>
dart:async-patch/timer_patch.dart 18:15 Timer._createTimer.<fn>
dart:isolate-patch/timer_impl.dart 398:19 _Timer._runTimers
dart:isolate-patch/timer_impl.dart 429:5 _Timer._handleMessage
dart:isolate-patch/isolate_patch.dart 184:12 _RawReceivePort._handleMessage
===== asynchronous gap ===========================
dart:async/zone.dart 1322:19 _CustomZone.registerCallback
dart:async/zone.dart 1248:22 _CustomZone.bindCallbackGuarded
dart:async/timer.dart 49:45 new Timer
package:rate_limiter/src/debounce.dart 96:7 Debounce._startTimer
package:rate_limiter/src/debounce.dart 150:14 Debounce._leadingEdge
package:rate_limiter/src/debounce.dart 213:16 Debounce.call
package:rate_limiter/src/throttle.dart 109:17 Throttle.call
package:electricsql/src/util/common.dart 25:22 Throttle.call
package:electricsql/src/satellite/process.dart 200:45 SatelliteProcess.start.<fn>
dart:async/future.dart 256:37 new Future.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 114:48 StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1391:47 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1209:7 _CustomZone.runGuarded
dart:async/zone.dart 1249:23 _CustomZone.bindCallbackGuarded.<fn>
package:stack_trace/src/stack_zone_specification.dart 207:15 StackZoneSpecification._run
package:stack_trace/src/stack_zone_specification.dart 114:48 StackZoneSpecification._registerCallback.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1233:23 _CustomZone.bindCallback.<fn>
dart:async-patch/timer_patch.dart 18:15 Timer._createTimer.<fn>
dart:isolate-patch/timer_impl.dart 398:19 _Timer._runTimers
dart:isolate-patch/timer_impl.dart 429:5 _Timer._handleMessage
dart:isolate-patch/isolate_patch.dart 184:12 _RawReceivePort._handleMessage
===== asynchronous gap ===========================
dart:async/zone.dart 1322:19 _CustomZone.registerCallback
dart:async/zone.dart 1248:22 _CustomZone.bindCallbackGuarded
dart:async/timer.dart 49:45 new Timer
dart:async/timer.dart 105:9 Timer.run
dart:async/future.dart 254:11 new Future
package:electricsql/src/satellite/process.dart 200:15 SatelliteProcess.start
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
package:electricsql/src/satellite/process.dart 156:7 SatelliteProcess.start
package:electricsql/src/satellite/registry.dart 210:21 GlobalRegistry.startProcess
package:electricsql/src/satellite/registry.dart 83:29 BaseRegistry.ensureStarted
package:electricsql/src/electric/electric.dart 80:36 electrifyBase
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
package:electricsql/src/electric/electric.dart 72:3 electrifyBase
package:electricsql/src/drivers/drift/drift.dart 33:41 electrify
package:electricsql_sandbox/electric.dart 22:28 Electric.init
test/dumb_test.dart 21:20 main.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
test/dumb_test.dart 19:5 main.<fn>
package:test_api/src/backend/declarer.dart 215:19 Declarer.test.<fn>.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
package:test_api/src/backend/declarer.dart 214:9 Declarer.test.<fn>.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:test_api/src/backend/declarer.dart 213:13 Declarer.test.<fn>
package:test_api/src/backend/invoker.dart 258:17 Invoker._waitForOutstandingCallbacks.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:test_api/src/backend/invoker.dart 254:5 Invoker._waitForOutstandingCallbacks
package:test_api/src/backend/invoker.dart 394:17 Invoker._onRun.<fn>.<fn>.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1329:19 _CustomZone.registerUnaryCallback
package:test_api/src/backend/invoker.dart 392:11 Invoker._onRun.<fn>.<fn>.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:test_api/src/backend/invoker.dart 383:9 Invoker._onRun.<fn>.<fn>
package:test_api/src/backend/invoker.dart 426:15 Invoker._guardIfGuarded
package:test_api/src/backend/invoker.dart 382:7 Invoker._onRun.<fn>
package:stack_trace/src/chain.dart 97:24 Chain.capture.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:stack_trace/src/chain.dart 95:12 Chain.capture
package:test_api/src/backend/invoker.dart 381:11 Invoker._onRun
package:test_api/src/backend/live_test_controller.dart 153:11 LiveTestController.run
package:test_api/src/backend/remote_listener.dart 273:16 RemoteListener._runLiveTest.<fn>
dart:async/zone.dart 1399:13 _rootRun
dart:async/zone.dart 1301:19 _CustomZone.run
dart:async/zone.dart 1804:10 _runZoned
dart:async/zone.dart 1747:10 runZoned
package:test_api/src/backend/remote_listener.dart 272:5 RemoteListener._runLiveTest
package:test_api/src/backend/remote_listener.dart 220:7 RemoteListener._serializeTest.<fn>
dart:async/zone.dart 1407:47 _rootRunUnary
dart:async/zone.dart 1308:19 _CustomZone.runUnary
dart:async/zone.dart 1217:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:async/zone.dart 1415:13 _rootRunUnary
dart:async/zone.dart 1308:19 _CustomZone.runUnary
dart:async/zone.dart 1217:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:async/stream_controller.dart 876:13 _StreamSinkWrapper.add
package:stream_channel/src/guarantee_channel.dart 125:12 _GuaranteeSink.add
package:stream_channel/src/multi_channel.dart 159:31 new _MultiChannel.<fn>
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:_internal/async_cast.dart 85:11 CastStreamSubscription._onData
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:async/stream_controller.dart 876:13 _StreamSinkWrapper.add
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_pipe.dart 123:11 _ForwardingStreamSubscription._add
dart:async/stream_pipe.dart 218:10 _MapStream._handleData
dart:async/stream_pipe.dart 153:13 _ForwardingStreamSubscription._handleData
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:_http/websocket_impl.dart 1144:21 new _WebSocketImpl._fromSocket.<fn>
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_transformers.dart 63:11 _SinkTransformerStreamSubscription._add
dart:async/stream_transformers.dart 13:11 _EventSinkWrapper.add
dart:_http/websocket_impl.dart 332:23 _WebSocketProtocolTransformer._messageFrameEnd
dart:_http/websocket_impl.dart 226:46 _WebSocketProtocolTransformer.add
dart:async/stream_transformers.dart 111:24 _SinkTransformerStreamSubscription._handleData
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:io-patch/socket_patch.dart 2447:41 _Socket._onData
dart:async/zone.dart 1594:10 _RootZone.runUnaryGuarded
dart:async/stream_impl.dart 339:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 271:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 784:19 _SyncStreamControllerDispatch._sendData
dart:async/stream_controller.dart 658:7 _StreamController._add
dart:async/stream_controller.dart 606:5 _StreamController.add
dart:io-patch/socket_patch.dart 1936:33 new _RawSocket.<fn>
dart:io-patch/socket_patch.dart 1379:14 _NativeSocket.issueReadEvent.issue
dart:async/schedule_microtask.dart 40:21 _microtaskLoop
dart:async/schedule_microtask.dart 49:5 _startMicrotaskLoop
package:drift/src/runtime/api/connection_user.dart 603:7 _extension#2.rollbackAfterException
===== asynchronous gap ===========================
dart:async _CustomZone.registerBinaryCallback
package:synchronized/src/basic_lock.dart 33:16 BasicLock.synchronized
package:electricsql/src/satellite/process.dart 143:26 SatelliteProcess._mutexSnapshot
dart:core Function.apply
package:rate_limiter/src/debounce.dart 92:31 Debounce._invokeFunc
package:rate_limiter/src/debounce.dart 120:14 Debounce._trailingEdge
package:rate_limiter/src/debounce.dart 139:7 Debounce._timerExpired
package:rate_limiter/src/debounce.dart 96:60 Debounce._startTimer.<fn>
===== asynchronous gap ===========================
dart:async new Timer
package:rate_limiter/src/debounce.dart 96:7 Debounce._startTimer
package:rate_limiter/src/debounce.dart 150:14 Debounce._leadingEdge
package:rate_limiter/src/debounce.dart 213:16 Debounce.call
package:rate_limiter/src/throttle.dart 109:17 Throttle.call
package:electricsql/src/util/common.dart 25:22 Throttle.call
package:electricsql/src/satellite/process.dart 200:45 SatelliteProcess.start.<fn>
===== asynchronous gap ===========================
dart:async new Future
package:electricsql/src/satellite/process.dart 200:15 SatelliteProcess.start
===== asynchronous gap ===========================
dart:async _CustomZone.registerUnaryCallback
package:electricsql/src/satellite/process.dart 156:7 SatelliteProcess.start
package:electricsql/src/satellite/registry.dart 210:21 GlobalRegistry.startProcess
package:electricsql/src/satellite/registry.dart 83:29 BaseRegistry.ensureStarted
package:electricsql/src/electric/electric.dart 80:36 electrifyBase
===== asynchronous gap ===========================
dart:async _CustomZone.registerUnaryCallback
package:electricsql/src/electric/electric.dart 72:3 electrifyBase
package:electricsql/src/drivers/drift/drift.dart 33:41 electrify
package:electricsql_sandbox/electric.dart 22:28 Electric.init
test/dumb_test.dart 21:20 main.<fn>
===== asynchronous gap ===========================
dart:async _CustomZone.registerUnaryCallback
test/dumb_test.dart 19:5 main.<fn>
from electric_dart.
@tpucci If you need the fix without the workaround you can use a dependency override in the meantime. Thank you for reporting!
dependency_overrides:
electricsql:
git:
url: https://github.com/SkillDevs/electric_dart
ref: dfb7d535f5bd3a9dbe224f01f7cd2e7dc5135a02
path: packages/electricsql
from electric_dart.
Thanks @davidmartos96 !
from electric_dart.
Related Issues (16)
- Supabase support HOT 21
- Schema versioning conflicts HOT 1
- Version solving failed in todos example HOT 3
- Supabase example
- Offine First, Sync Optional HOT 4
- Show us your projects using electric_dart HOT 1
- Electric custom types (eg, Postgres date type) not generating correct SQL for query. HOT 3
- [How to] Use the latest master version, skipping the pub.dev HOT 2
- Todos_flutter errors HOT 3
- [CLI] cant use custom .env file HOT 2
- Not updating views with streambuilder HOT 14
- Bad state: No element when generating tables. HOT 8
- Error connecting to Electric: errorType: INVALID_REQUEST when pressing back button on main screen and reopening the app HOT 12
- Issue after upgrade `_electric_trigger_settings has no column named namespace` HOT 5
- MODULE ERROR: Electric.Replication.PostgresConnector when trying to connect to Supabase HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electric_dart.