Skip to content

Crash when connection to MySQL db is interrupted #20

Open
@renblau

Description

@renblau

I have noticed that all of my servers that are running the current sqljocky5 version crash from time to time. The connection to MySQL gets interrupted for whatever reason (e.g. mysqld restart). Then, when the program tries to execute a query, this happens:

Unhandled exception:
Bad state: Cannot write to socket, it is closed
#0      BufferedSocket.writeBufferPart (package:sqljocky5/comm/buffered_socket.dart:112:7)
#1      BufferedSocket.writeBuffer (package:sqljocky5/comm/buffered_socket.dart:107:12)
#2      Sender._sendBufferPart (package:sqljocky5/comm/sender.dart:57:19)
<asynchronous suspension>
#3      Sender.send (package:sqljocky5/comm/sender.dart:45:14)
<asynchronous suspension>
#4      Comm._processHandler (package:sqljocky5/comm/comm.dart:114:19)
<asynchronous suspension>
#5      Comm.execHandler.<anonymous closure> (package:sqljocky5/comm/comm.dart:120:36)
#6      new Future.sync (dart:async/future.dart:224:31)
#7      Pool.withResource.<anonymous closure> (package:pool/pool.dart:126:18)
#8      _RootZone.runUnary (dart:async/zone.dart:1379:54)
#9      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#11     Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#12     Future._completeWithValue (dart:async/future_impl.dart:483:5)
#13     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:513:7)
#14     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#15     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#16     _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#17     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

Furthermore, I wasn't able to catch the error to handle it myself (i.e. create a new connection and retry the query):
Edit: That was my fault, catching works fine. I guess I have to implement a reconnect mechanism into my application now.

Would be cool though if the library detected disconnects itself. Ideally before the user is trying to execute a query. Something like: _connection.onDisconnect.listen( ... )

Activity

tejainece

tejainece commented on Feb 15, 2019

@tejainece
Contributor

I will fix this.

self-assigned this
on Feb 15, 2019
hoylen

hoylen commented on Feb 19, 2019

@hoylen

This goal is related to the "unhandled exception" reported in #26. But the specific exception is different, since I can't seem to catch the other exception (not without trying to use zones etc.).

tejainece

tejainece commented on Feb 19, 2019

@tejainece
Contributor

@renblau
onDisconnect is a brilliant idea.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Crash when connection to MySQL db is interrupted · Issue #20 · dart-db/sqljocky5