Hello. Has anybody tried to reuse a connection, that was made by Client::new()
? I’m getting an error “Failed to receive transfer due to InvalidTransfer(\“Internal messaging channel was dropped\”)” on call to Client::receive()
. Client was kept in Tauri managed state. Same operations in immediate form (connect, load wallet, receive – one after another) resulted in a successful cashnotes reception.
I think the only API usecase till now was CLI app, so perhaps a Client
object is not tested for long-lasting reuse, in that case it should be stated in docs somewhere that it’s not suitable, or this should be considered as bug.
I haven’t tried. I currently use a new client/connection for each user interaction.
Be useful to have a way to avoid that.
I also haven’t tried Tauri managed state so would be interested to see how you are using it. I keep state in Rust LazyStatic’s and provide accessor functions for the front end.
I made a lib, where in Safe structure the Client is kept, so:
struct Safenet {
safe: Mutex<Safe>,
}
then after I connect (s is a Safe
struct, and app is a &mut tauri::App
or another Manager):
app.manage(Safenet {
safe: Mutex::new(s),
});
then in a command you can use it:
#[tauri::command]
async fn do_something(safenet: State<'_, Safenet>) -> Result<(), Error> {
safenet.safe.lock().await
.some_safe_method()
.await?;
Ok(())
}
That’s pretty much what I’m doing, but without app.manage()
(and not for the Client, just some state variables used by front and back end.) I hadn’t looked into it, so thought that would give access directly in the front end too.
Oh, and it’s important to use Mutex
from a futures lib, I had a lot of problems until I found a solution for that.
Edit:
Perhaps a tauri Mutex is even better, which is in fact a pub use
of tokio’s Mutex.
I keep the connections open for long periods of time in sn_httpd.
I haven’t observed any connections dropping. They are just opened when the web server starts and remain until shutdown, iirc.
Perhaps Tauri or futures::Mutex is doing something with Client, so that it loses a connection…
I found a solution, or rather a workaround.
Now I call Client::new()
in a Tauri command, as other operations, instead of inside tauri::Builder::setup()
.