Glacier2.Application - Ice.ConnectionLostException

kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers

Hi,

I'm currently facing the following problem: I'm using an Ice-Client, that extends Glacier2.Application in Java 8, Ice 3.6.3.

Now I have a test scenario, where I e.g. deactivate my network adapter to simulate network connection problems.

At the next call of a Glacier2.Application-method an Ice.ConnectionLostException is thrown.

-! 19.01.18 14:47:03:705 Client: warning: Ice.ThreadPool.Client-1: connection exception:
local address = 192.168.8.222:53702
remote address = 192.168.8.106:4064
Ice.ConnectionLostException
error = 0
at IceInternal.StreamSocket.read(StreamSocket.java:207)
at IceInternal.StreamSocket.read(StreamSocket.java:153)
at IceInternal.TcpTransceiver.read(TcpTransceiver.java:57)
at Ice.ConnectionI.read(ConnectionI.java:2821)
at Ice.ConnectionI.message(ConnectionI.java:844)
at IceInternal.ThreadPool.run(ThreadPool.java:395)
at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Operation timed out
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at IceInternal.StreamSocket.read(StreamSocket.java:189)
... 8 more

How can I catch this exception in order to include an error-logging e.g.?

Regards

Klaus

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff

    Hi Klaus,

    You can disable this warning by setting Ice.Warn.Connections=0. When the connection loss is detected, Glacier2.Application.sessionDestroyed() is called. You can override this method to be notified as soon as the connection loss is detected by Ice. To get the exception, you can try making an ice_ping call on the router proxy. For example:

        @Override
        public void sessionDestroyed()
        {
            try
            {
                router().ice_ping();
            }
            catch(Ice.LocalException ex)
            {
                // ...
            }
        }
    

    Cheers,
    Benoit.

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers
    edited January 19

    Hi Benoit,

    ok thanks, I'll give it a try.

    I have another question concerning the glacier2 application. (I used the demo under https://github.com/zeroc-ice/ice-demos/tree/master/java/Glacier2 as a starting point.)

    I have a system where I would like to automatically inform all 'connected clients' about e.g. system updates.

    The way I'm doing that is, that my Ice Client (extends Glacier2.Application) sends a ping every e.g. 10 seconds to the the server (extends Ice.Application) with a reference of the CallbackReceiverPrx twowayR-variable as a parameter. The servers CallbackI has a thread-safe data structure with a list of all of these CallbackReceiverPrx-objects. In case of a notfication to all clients, the CallbackI-method (e.g. informAll) goes through all CallbackReceiverPrx-objects and calls their callback-method.

    Is that a good way to accomplish this, e.g. from connection management point of view?

    Regards Klaus

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff

    Hi Klaus,

    Instead of having the client pinging the server every 10s to provide its callback receiver proxy, I recommend to implement sessions on the server side and store the callback proxy once and for all with the server side session servant. The session object on the server side will allow you to store other client related state as well and to clean up any state related to the client when the session is destroyed.

    I recommend you to check out the Glacier2 simpleChat demo instead, it demonstrates this although we don't provide a Java version of the server but only C++. See https://github.com/zeroc-ice/ice-demos/tree/master/cpp11/Glacier2/simpleChat

    In this demo, you'll see that the client creates a session on the server and provides its callback proxy once with the ChatSession::setCallback method.

    Cheers,
    Benoit.

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers

    Ok thanks,

    I've implemented the simple-Chat server in Java and used for the client

    https://github.com/zeroc-ice/ice-demos/tree/master/java/Glacier2/simpleChat

    What I'm observing now is that, e.g. when I deactivate the network adapter of a client, the server recognises the inactive session after Glacier2.SessionTimeout property - but the client does not. When I for example shutdown the server the client recognises it.

    Do you know how I can accomplish, that client also recognises when I deactivate network adapter?

    Regards Klaus

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers

    If I set the Ice.Default.InvocationTimeout property and periodically call a _chat.ice_ping() I get the InvocationTimeoutException to detect network-adapter deactivations.

    Is this a appropriate way to handle this?

    Regards Klaus

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff

    Hi,

    The disconnected should be called in theory when the client gets disconnected from the Glacier2 router. Isn't this method called?

    You can enable Ice.Trace.Network=2 in the config.client to monitor when the network connection gets established and disconnected.

    Cheers,
    Benoit.

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers
    edited January 25

    Hi,

    when i e.g. shutdown the server, network connection gets closed at the client.

    -- 25.01.18 10:14:13:161 Network: closed tcp connection
    local address = 192.168.8.222:49235
    remote address = 192.168.8.106:4064
    com.zeroc.Ice.ConnectionLostException
    error = 0
    -- 25.01.18 10:14:13:162 Network: trying to establish tcp connection to 192.168.8.106:4064
    -- 25.01.18 10:14:13:166 Network: established tcp connection
    local address = 192.168.8.222:49236
    remote address = 192.168.8.106:4064
    -- 25.01.18 10:14:13:170 Network: closed tcp connection
    local address = 192.168.8.222:49236
    remote address = 192.168.8.106:4064

    When I deactivate the WLAN-adapter at the client, server detects and destroys session, but client on Mac OS 10.9.5 with ICE 3.7.0 does not.

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers

    Ok, I'm sorry - indeed the disconnected is called, but quite lately.... and obviously session!=_session is true in the disconnected SessionCallback.

    I get the following output in the console:

    -- 25.01.18 14:12:13:017 Network: closed tcp connection
    local address = 192.168.8.222:49379
    remote address = 192.168.8.106:4064
    com.zeroc.Ice.ConnectionLostException
    error = 0
    -- 25.01.18 14:12:13:019 Network: trying to establish tcp connection to 192.168.8.106:4064
    -- 25.01.18 14:12:13:019 Network: failed to establish tcp connection to 192.168.8.106:4064
    com.zeroc.Ice.SocketException
    error = 0
    -- 25.01.18 14:12:13:019 Network: connection to endpoint failed and no more endpoints to try
    com.zeroc.Ice.SocketException
    error = 0
    -! 25.01.18 14:12:13:020 warning: Thread-11: SessionHelper: unexpected exception when destroying the session:
    com.zeroc.Ice.SocketException
    error = 0
    disconnect called

    Is there a property which defines the timeout when the ConnectionLostException is thrown?

    Regards Klaus

  • kdobbkdobb Member Klaus DobblerOrganization: personProject: the project is for the synchronization of files in network with multiple peers

    Hi Benoit,

    after integrating the sessions on the server side based on simpleChat-Demo everything works fine! Thanks!

Sign In or Register to comment.