# InterprocessConnection shutdown calls connectionLost

**URL:** <https://forum.juce.com/t/interprocessconnection-shutdown-calls-connectionlost/54506>\
**Category:** General JUCE discussion\
**Created:** [January 13, 2023, 4:44am UTC](https://forum.juce.com/t/interprocessconnection-shutdown-calls-connectionlost/54506 "2023-01-13T04:44:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmelon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bmelon/32/2455_2.png) [@bmelon](https://forum.juce.com/u/bmelon)\
**Post date:** [January 13, 2023, 4:44am UTC](https://forum.juce.com/t/interprocessconnection-shutdown-calls-connectionlost/54506/1 "2023-01-13T04:44:02Z")

</div>

I have a class Foo that inherits from InterprocessConnection. My Foo::connectionLost has “error recovery” code that is intended to try to re-establish the connection. As instructed by the documentation, I call disconnect in my ~Foo destructor, but I take care to turn off the notification because when destroying Foo I am intentionally disconnecting and my application is “done”. I don’t want the error recovery to kick in and try to re-establish the connection. So I have  
disconnect(1000, InterprocessConnection::Notify::no);  
…in ~Foo().

The problem is this code in InterprocessConnection::runThread()

```auto
            auto ready = socket->waitUntilReady (true, 100);

            if (ready < 0)
            {
                deletePipeAndSocket();
                connectionLostInt();
                break;
            }

```

When the InterprocessConnection is destroyed, ready the socket returns a negative value and connectionLostInt() gets called. That unconditionally calls connectionLost and now my error recovery tries to execute to re-establish the connection while the object is being deleted and chaos ensues.

It seems like connection recovery code might be common in connectionLost and so possibly this is a common use case that needs to be addressed?
