Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconnection only works if the server disconnected for few seconds not for a minute and above. #248

Closed
TomieAi opened this issue Oct 20, 2022 · 5 comments

Comments

@TomieAi
Copy link

TomieAi commented Oct 20, 2022

it do nothing. when I try turn off server for 15 seconds. I tried to do .reconnect(true) .max_reconnect_attempts(0) also and the reconnect_delay(3, 5) maybe it helps. it dint.

btw what I mean by "not working is" well its doing nothing no error what so ever. I know it dint reconnect because server dint log the client socket id at connection event. and client surely dint receive the emit test I send to any client that successfully pass the connection event.

if I turn off/on server quick seconds again and again.. that's fine.. the reconnection is working chief kiss <3.. but when its longer than that.. 15s+. it doesn't do anything.

I really like the socket client JS behavior's that it keeps reconnecting no matter what happen like u will get a lot of xD connection error at console. like it keeps knocking to the door or hitting the door bell until server responded back.

help me out maybe I'm missing something.

also I realize auto reconnect only covers the part where you got disconnected not when u failed to connect on 1st run.

@SSebo
Copy link
Contributor

SSebo commented Oct 21, 2022

@TomieAi I turn off server for several minutes, and start again, reconnect works. Could you show me a demo code to reproduce the scenario?
BTW, currently emit will return Error::IllegalActionBeforeOpen if connection is down, so you should handle the result, make sure your code not exist early. #230

@TomieAi
Copy link
Author

TomieAi commented Oct 21, 2022

I turn off server for several minutes, and start again, reconnect works. Could you show me a demo code to reproduce the scenario?

weird xD its working fine right now xD yesterday it dint. 🤯 like the test yesterday is consistent.. sorry about it :(

one last thing before I close this issue..

if I expect the server to be offline after I start client..
client should try to reconnect and hoping to ignore this.

thread 'main' panicked at 'Connection failed: IncompleteResponseFromEngineIo(IncompleteResponseFromReqwest(reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(3000), path: "/socket.io/", query: Some("EIO=4&transport=polling&t=2169245116"), fragment: None }, source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." })) }))', src\main.rs:26:10

is it ok by design to do this? call the main again. to ignore the error above?

use rust_socketio::{ClientBuilder, Payload, RawClient};
use serde_json::json;
use std::io;

fn main() {
    let callback = |payload: Payload, socket: RawClient| {
        match payload {
            Payload::String(str) => println!("Received: {}", str),
            Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data),
        }
        socket
            .emit("test", json!({"got ack": true}))
            .expect("Server unreachable")
    };

    // get a socket that is connected to the admin namespace
    let test = ClientBuilder::new("http://localhost:3000")
        .namespace("/")
        .on("test", callback)
        .on("error", |err, _| {
            eprintln!("Error: {:#?}", err);
        })
        .connect();

    if test.is_err() {
        println!("rc");
        main();
    }

    io::stdin().read_line(&mut String::new()).unwrap();
}

tbh im not really good at rust im a c++xD i just really wanna convert the client I made from using this https://github.com/socketio/socket.io-client-cpp but in rust.. because I find rust very interesting.

@SSebo
Copy link
Contributor

SSebo commented Oct 21, 2022

As the socketio doc said https://socket.io/docs/v3/client-socket-instance/, first time connect failed will not reconnect, must be manual reconnect, reconnect should only after previous connect is succeed.

@1c3t3a
Copy link
Owner

1c3t3a commented Oct 21, 2022

Yes, this is definitely not the intended behavior! If the server is not available you should be notified and not try to reconnect forever!!

@TomieAi
Copy link
Author

TomieAi commented Oct 21, 2022

As the socketio doc said https://socket.io/docs/v3/client-socket-instance/, first time connect failed will not reconnect, must be manual reconnect, reconnect should only after previous connect is succeed.

Yes, this is definitely not the intended behavior! If the server is not available you should be notified and not try to reconnect forever!!

aight thank you I will do manual reconnect.

I think I'm in the wrong here and confused and I'm sorry xD haha I've never really use the real client of socket.io..

but instead I use this ..

#angular (web)
https://www.npmjs.com/package/ngx-socket-io
#c++ (desktop)
https://github.com/socketio/socket.io-client-cpp

both of them will still reconnect even tho the server is not up xD because of that I assume that's the same behavior's across all client.. again sorry xD my bad.. I dint read the lifecycle on the real socket.io client

image

and you guys are right base on lifecycle image of socket.io client it should not do this xD I just get confused i thought its the same behavior for all clients my bad.

image

aight im gonna close this up.

@TomieAi TomieAi closed this as completed Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants