bridge.py stops after three telent connections

I have a simple Console program that I’d like to connect to periodically using ‘telnet localhost 6571’ from a ssh session. Only trouble is, is that after connecting and disconnecting 3 times, bridge.py no longer starts without resetting the MCU on the Yun.

Does anyone have any suggestions or recommendations, and, or, has anyone else run into this.

/*
 *  To see the Console, pick your Yún's name and IP address in the Port menu
 *  then open the Port Monitor. You can also see it by opening a terminal window
 *  and typing:
 *  ssh root@ yourYunsName.local 'telnet localhost 6571'
 *  then pressing enter. When prompted for the password, enter it.
 */
 
#include <Console.h>

void setup() {

  // Initialize Console:
  Bridge.begin();
  Console.begin();

}

void loop() {
  // put your main code here, to run repeatedly:

    static long waitPeriod = millis();
 
    if (millis() >= waitPeriod)
    {
        // test for bridge.py running?, start if needed.
        if (!Console) Console.begin();  

        // if we have a connection update the status page
        if(Console)
        {
            Console.println("*** Status Update ***");
            Console.println(millis());  
        }
        waitPeriod = millis() + 5000; // rerun this code to update Terminal in another 50ms time.
    }
  
}

if I take out the code block:

// test for bridge.py running?, start if needed.
        if (!Console) Console.begin();

telnet fails to reconnect after the first disconnect.

root@mhm002:/tmp# telnet localhost 6571
telnet: can't connect to remote host (127.0.0.1): Connection refused

Eventually I’d plan to display values from sensors, but if I can’t get past this…

Thanks

I noticed this in the bridge error log after a failure to reconnect:

root@mhm002:/tmp# cat bridge.py-stderr.log
Traceback (most recent call last):
File “bridge.py”, line 87, in
res = pr.process()
File “/usr/lib/python2.7/bridge/packet.py”, line 123, in process
self.processor.run()
File “bridge.py”, line 49, in run
runner.run()
File “/usr/lib/python2.7/bridge/console.py”, line 60, in run
self.socket_receive(sock)
File “/usr/lib/python2.7/bridge/console.py”, line 78, in socket_receive
chunk = client.recv(1024)
socket.error: [Errno 131] Connection reset by peer

@cfo215, have you resolved your issue? Jesse

I had the same error, and found your post.

In /usr/lib/python2.7/bridge/console.py I edited line 78 which was indicated in the logs above to: -

    try:
      chunk = client.recv(1024)
    except:
      chunk = ''

This solved the problem for me, though I didn't look for the wider issue, so the solution may not be ideal. There might be a better place to catch the expression earlier in the stack.