question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Detect closed server connection and automatically reconnect.

See original GitHub issue

I have a simple setup between two services that I’ve built from provided examples. I have one service that listens for incoming connections:

        TcpServerTransport tcp = TcpServerTransport.create(configProps.getPort());
        RSocketFactory.receive()
                .acceptor(itemSocketAcceptor)
                .transport(tcp)
                .start().log()
                .subscribe();

Another service attempts to make a connection:

        this.socket = RSocketFactory
                .connect()
                .transport(TcpClientTransport.create(<host>, <port>)
                .start()
                .block();

If I redeploy the receiving service, the client service never reports an error (unless I set a timeout on the requestResponse method). I can’t seem to find a way for the client side to detect that the underlying connection has closed and to automatically try to reconnect. To boot, these are web applications in Spring Boot, so I’m never able to attempt to call block() during a web request.

The onClose method seems to be an indicator that the connection has closed, but I’m not sure how to use that in the context of a web request to be able to attempt to rebuild the connection which necessarily requires me to call block.

Not sure if this is an actual issue or if I’ve simply overlooked some documentation or examples. I’m anxious to adopt rsocket in my company, so any direction would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:27 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
joshfixcommented, Oct 28, 2018

@mostroverkhov I believe that is correct. Before using the load balancer, there never seemed to be an error on the client side if the server was restarted; it would just hang (seemingly indefinitely). If I set a timeout on the request, I would see the timeout exception, but I could not find any good way to tell the client to attempt to reconnect after the server side had restarted.

I was using roscket-core and rsocket-transport-netty 0.11.7 and just noticed that I was using rsocket-load-balancer 0.11.8. 0.11.9 does not appear to be on maven central. I’ll update everything to 0.11.8 and restest/reverify the issue.

1reaction
robertroesercommented, Oct 26, 2018

@joshfix Don’t block on the loadbalancer - you need to subscribe to it each time so it can load balance and what not.

Should be more like this:

log.info("Attempting RSocket connection to " + configProps.getHost() + ":" + configProps.getPort());
        Mono<RSocket> mono = LoadBalancedRSocketMono
                .create(Flux.just(Collections.singleton(new RSocketSupplier(() -> RSocketFactory
                        .connect()
                        .transport(TcpClientTransport.create(configProps.getHost(), configProps.getPort()))
                        .start()
                        .doOnSubscribe(s -> log.info("RSocket connection established.", s))))))
    }

 public Mono<Item> getItem(String id) {
        log.debug("Requesting item from STAC with id " + id);
        return mono.flatMap(socket -> 
              socket
                .requestResponse(DefaultPayload.create(id)).log()
                .timeout(Duration.ofSeconds(10))
                .map(this::deserializeItem)
       );
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto-reconnecting and detecting socket disconnection - MSDN
Hello. I'm currently using TcpClient to make my socket connection to a TCP server and this itself appears to work fine.
Read more >
Instantly detect client disconnection from server socket
BeginReceive() on the server program and then the client closed the connection "gracefully", your receive callback will be called and EndReceive() will ...
Read more >
Enabling Server Auto-reconnect - Micro Focus
If a client loses its network connection, users are disconnected from the Server. The reconnect time-out option determines the amount of time the...
Read more >
Automatic client reconnection - IBM
Automatic client reconnection is inline. The connection is automatically restored at any point in the client application program, and the handles to open ......
Read more >
Tool to check VPN connection and reconnect if disconnected?
VPN Reconnect is a new feature of Routing and Remote Access Services (RRAS) in Windows® 7 or Windows Server® 2008 R2 that provides...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found