dartssh2
dartssh2 copied to clipboard
Connection blocks main thread
For some reasons the use of dartssh2 blocks the main thread of my flutter application. This happens when I connect to the server and when I run a simple command on the server e.g. cat file.txt which is very small (like 100 characters). I run my application with a debugger and stopped it during the hangs. For the connection it seems that the loading of the ssh key takes quite some time, for the cat I not that sure.
Since dart has just one thread und there are no async calls in between, the main application hangs. Is there something I can to to prevent the hangs?
Connect to the server:
F (bcrypt.dart:1242)
Blowfish.encipher (bcrypt.dart:1154)
Blowfish.expand0state (bcrypt.dart:1193)
bcrypt_hash (bcrypt.dart:1267)
bcrypt_pbkdf (bcrypt.dart:1343)
OpenSSHKeyPairs._decryptPrivateKeyBlob (ssh_key_pair.dart:213)
OpenSSHKeyPairs.getPrivateKeys (ssh_key_pair.dart:138)
SSHKeyPair.fromPem (ssh_key_pair.dart:24)
ServerConnection._connect (connection.dart:23)
Run command cat:
int.+ (integers.dart:8)
TweetNaCl._M_off (tweetnacl.dart:1184)
TweetNaCl._M (tweetnacl.dart:803)
TweetNaCl.crypto_scalarmult (tweetnacl.dart:1394)
TweetNaCl.crypto_scalarmult_base (tweetnacl.dart:1416)
_ScalarMult.scalseMultBase (kex_x25519.dart:63)
new SSHKexX25519 (kex_x25519.dart:18)
SSHTransport._handleMessageKexInit (ssh_transport.dart:714)
SSHTransport._handleMessage (ssh_transport.dart:637)
SSHTransport._processPackets (ssh_transport.dart:317)
SSHTransport._processVersionExchange (ssh_transport.dart:300)
SSHTransport._processData (ssh_transport.dart:257)
SSHTransport._onSocketData (ssh_transport.dart:237)
_rootRunUnary (zone.dart:1434)
_CustomZone.runUnary (zone.dart:1335)
_CustomZone.runUnaryGuarded (zone.dart:1244)
_BufferingStreamSubscription._sendData (stream_impl.dart:341)
_BufferingStreamSubscription._add (stream_impl.dart:271)
_SyncStreamControllerDispatch._sendData (stream_controller.dart:774)
_StreamController._add (stream_controller.dart:648)
_StreamController.add (stream_controller.dart:596)
_Socket._onData (socket_patch.dart:2314)
_rootRunUnary (zone.dart:1442)
_CustomZone.runUnary (zone.dart:1335)
_CustomZone.runUnaryGuarded (zone.dart:1244)
_BufferingStreamSubscription._sendData (stream_impl.dart:341)
_BufferingStreamSubscription._add (stream_impl.dart:271)
_SyncStreamControllerDispatch._sendData (stream_controller.dart:774)
_StreamController._add (stream_controller.dart:648)
_StreamController.add (stream_controller.dart:596)
new _RawSocket.
P.S.: My ssh key is an 4096 RSA key. With https://pub.dev/packages/ssh2 I did not had these problem, but there the release version of my App was not working properly.
The algorithm used in encrypted private keys is bcrypt, which is a password hashing algorithm and is slow by design. You can use the compute
function to move the computation to other isolates, as described in README.
Thanks for the answer. Using the compute to load the key solver the issue with the connection.
What do you mean in "bcrypt, which is a password hashing algorithm and is slow by design" with "slow by design". Slow in order to take long or slow because it needs a lot of computations?
Nevertheless, the application still hangs on the cat of the file.
@Nihildum did you find a solution? I have the same issue with any interaction of the package
I switched technology in my project. The ssh connection to the server was used in first prototype. When I implemented a real server with protobuf, I no longer neded the dartssh2 package.
Unfortunately I don't have that option
@xtyxtyx I am just using username
& onPasswordRequest
. Is there a way to prevent the main thread from blocking? Or do you have an idea on how we can prevent this in general?