exception connection reset

1,578 views
Skip to first unread message

sara

unread,
Aug 23, 2014, 2:41:39 AM8/23/14
to rabbitm...@googlegroups.com
hi.
i use federation plugin and i create upstream from on cp(node1) to another (node2).
important thing for me is that,if internet disconnected,i don't loos any message.
for testing ,i write sample test for publish msg in n ode1 and sample test for consuming in node2.when internet in node1(upstream )disconnected.after 30 min i get this exception in node2(downstream.)


Exception in thread "main" com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketException: Connection reset
at com.rabbitmq.client.QueueingConsumer.handle(QueueingConsumer.java:198)
at com.rabbitmq.client.QueueingConsumer.nextDelivery(QueueingConsumer.java:215)
at Consumer.main(Consumer.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at java.io.DataInputStream.readFully(DataInputStream.java:195)
at java.io.DataInputStream.readFully(DataInputStream.java:169)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:117)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:131)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:515)

how can i catch connection reset in my code?
also 
log of server is :

=SUPERVISOR REPORT==== 9-Aug-2014::20:20:14 ===
     Supervisor: {<0.228.0>,
                                           rabbit_federation_link_sup}
     Context:    child_terminated
     Reason:     {shutdown,restart}
     Offender:   [{pid,<0.231.0>},
                  {name,
                      {upstream,
                          [<<"amqp://192.168.1.158:61256">>],
                          <<"metrics.user_login">>,<<"metrics.user_login">>,
                          1000,1,1,none,none,false,'on-confirm',none,
                          <<"sa-upstream">>}},
                  {mfargs,
                      {rabbit_federation_exchange_link,start_link,
                          [{{upstream,
                                [<<"amqp://192.168.1.158:61256">>],
                                <<"metrics.user_login">>,
                                <<"metrics.user_login">>,1000,1,1,none,none,
                                false,'on-confirm',none,<<"sa-upstream">>},
                            {resource,<<"/">>,exchange,
                                <<"metrics.user_login">>}}]}},
                  {restart_type,{permanent,1}},
                  {shutdown,4294967295},
                  {child_type,worker}]


Michael Klishin

unread,
Aug 23, 2014, 3:48:45 AM8/23/14
to rabbitm...@googlegroups.com, sara
On 23 August 2014 at 10:41:45, sara (hajil...@gmail.com) wrote:
> > how can i catch connection reset in my code?

Add a shutdown listener or enable automatic connection recovery
(Java client 3.3.0+) or use Spring AMQP (which supports recovery as well).

http://www.rabbitmq.com/api-guide.html 

> also
> log of server is :

This simply means that a federation link detected a failed connection.
It will be restarted.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

sara

unread,
Aug 23, 2014, 6:50:08 AM8/23/14
to rabbitm...@googlegroups.com
hi again.
i added this part to my code,but about 1 min after internet disconnected,i see again exception.time out exception.
what is problem?



 connection = factory.newConnection();
            connection.addShutdownListener(new ShutdownListener() {
                public ScheduledExecutorService executor;

                @Override
                public void shutdownCompleted(ShutdownSignalException e) {
                    //To change body of implemented methods use File | Settings | File Templates.
                    if(e.isHardError())
                    {
                        Connection connection=(Connection) e.getReference();
                        if(!e.isInitiatedByApplication())
                        {
                            Method reason= (Method) e.getReason();
                        }
                    }
                    else
                    {

                        Channel channel=(Channel) e.getReference();
                        System.out.print("channel is"+channel);
                    }
                }
            });

Michael Klishin

unread,
Aug 23, 2014, 6:52:15 AM8/23/14
to rabbitm...@googlegroups.com, sara
 On 23 August 2014 at 14:50:14, sara (hajil...@gmail.com) wrote:
> > i added this part to my code,but about 1 min after internet disconnected,i
> see again exception.time out exception.
> what is problem?

We can't tell that without seeing the error message, stack trace, and what's
in RabbitMQ logs around the time it happens.

I highly recommend using the automatic recovery feature (you can add your
own shutdown listeners for logging, of course).

sara

unread,
Aug 23, 2014, 7:02:39 AM8/23/14
to rabbitm...@googlegroups.com, hajil...@gmail.com

or using  automatic recovery feature,i added  artifact to maven.but in program ,intelliJidea doesn't know this."factory.setAutomaticRecoveryEnable(true);" and setAutomaticRecoveryEnable became red.!    and when press  alt+enter i see:"introduce local variable"
maven dependency:

 <dependency>
        <groupId>com.rabbitmq</groupId>
        <artifactId>amqp-client</artifactId>
        <version>3.3.4</version>
    </dependency>

Michael Klishin

unread,
Aug 23, 2014, 7:07:28 AM8/23/14
to rabbitm...@googlegroups.com, sara
On 23 August 2014 at 15:02:45, sara (hajil...@gmail.com) wrote:
> > or using automatic recovery feature,i added artifact to maven.but
> in program ,intelliJidea doesn't know this."factory.setAutomaticRecoveryEnable(true);"
> and setAutomaticRecoveryEnable became red.! and when press
> alt+enter i see:"introduce local variable"
> maven dependency:
>
>
> com.rabbitmq
> amqp-client
> 3.3.4

Automatic recovery was introduced in 3.3.0:
https://www.rabbitmq.com/releases/rabbitmq-java-client/v3.3.5/rabbitmq-java-client-javadoc-3.3.5/com/rabbitmq/client/ConnectionFactory.html#setAutomaticRecoveryEnabled(boolean)

Check that your pom.xml is in sync with IDEA (right-click on pom.xml, then
Add as Maven Project or Maven > Reimport), or add the dependency to your IDEA module.

sara

unread,
Aug 23, 2014, 9:03:51 AM8/23/14
to rabbitm...@googlegroups.com, hajil...@gmail.com
tnx.it solved.it was because of intelliJ idea.
now i have new exception time out!
i set that  factory.setConnectionTimeout(999999999);
but again i have this exception!how to catch that?

Michael Klishin

unread,
Aug 23, 2014, 9:11:15 AM8/23/14
to rabbitm...@googlegroups.com, sara
On 23 August 2014 at 17:03:57, sara (hajil...@gmail.com) wrote:
> > i set that factory.setConnectionTimeout(999999999);

This is for initial connection timeout, not heartbeats. For heartbeats
you need to use setRequestedHeartbeat (and such high values make
no sense, given that the feature exists primarily to quickly detect
unresponsive peers). 

> but again i have this exception!how to catch that?

What is in RabbitMQ logs? (I've asked this before).

Please understand that this is not a client issue: for some reason,
TCP connection to RabbitMQ is reset. It can be due to a variety of reasons
but the primary suspects are:

 * An intermediary (proxy, firewall, etc) terminates it
 * RabbitMQ is shut down abruptly

Inspecting RabbitMQ log should give you some clues.
Reply all
Reply to author
Forward
0 new messages