homemate-bridge icon indicating copy to clipboard operation
homemate-bridge copied to clipboard

RuntimeError: can't start new thread

Open bwduncan opened this issue 7 years ago • 2 comments

Hi,

I'm using homemate-bridge 0.1.1 on a raspberry pi with three orvibo sockets (B20UK I think). After a while (it's been running for 24 days), I start seeing lots of these exceptions in the logs:

Traceback (most recent call last): File "/usr/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python3.5/socketserver.py", line 636, in process_request t.start() File "/usr/lib/python3.5/threading.py", line 844, in start _start_new_thread(self._bootstrap, ()) RuntimeError: can't start new thread

It looks like each socket is opening a new TCP connection every few hours (the time between connections is quite irregular, usually not less than an hour, usually not more than 6 hours).

Currently homemate-bridge has 250 TCP connections open, and 251 threads.

I appreciate that this might be difficult to reproduce, and I'm not sure what the fix is: Perhaps closing connections which haven't seen any traffic for hours is an easy fix? That would simply involve setting the timeout attribute to a number of seconds (3600, one hour?) on the server object in main. What do you think?

Thanks, Bruce

bwduncan avatar Jan 26 '18 12:01 bwduncan

Hi,

Thanks for the bug report. I suspect that I'm not cleaning up connections correctly; your suggestion sounds reasonable as a stop-gap. I'll make the change today, and I've you a version to test to see if it fixes the problem

Thanks, Will

insertjokehere avatar Jan 27 '18 23:01 insertjokehere

I've pushed 3b23e90 which should fix this issue.

Thinking about it a bit more, the timeout needs to be on the handler class, not the server. Setting a timeout on the server just causes a callback to be fired if no new connections have been made within the defined time, we want to clean up old connections that have been hanging around for too long

@bwduncan can you try installing the latest master (pip install git+git://github.com/insertjokehere/homemate-bridge.git@master) and see if that fixes the problem you were having?

insertjokehere avatar Jan 28 '18 05:01 insertjokehere