wisespace-io / binance-rs

Rust Library for the Binance API
Other
665 stars 297 forks source link

panic on losing internet connection in websockets #24

Closed jcageman closed 5 years ago

jcageman commented 5 years ago

When running websockets event_loop() and any errors occur the program panics immediately, it would be nice to be able to recover from such an error and try connecting again to the websockets api. Here everything is being unwrapped, instead of actually returning an error in the event_loop such that any external caller could recover from them. websockets.rs: let msg: String = socket.0.read_message().unwrap().into_text().unwrap();

wisespace-io commented 5 years ago

@jcageman yes, definitely. I noticed that I do some check in the bitfinex event_loop and also has on_error event

https://github.com/wisespace-io/bitfinex-rs/blob/master/src/websockets.rs#L201

wisespace-io commented 5 years ago

@jcageman I updated the library, so we should be able to catch the disconnection errors. Please check the latest version and the examples. Once you get the error you can decide your re-connection strategy.

For example, it may sleep for 5 seconds and try to connect again, see how I handle such behaviour in my another crate

https://github.com/wisespace-io/nettfiske/blob/master/src/main.rs#L114

jcageman commented 5 years ago

@wisespace-io thanks for the fix! I already fixed it locally, but i prefer to depend directly on the github version!