Comments (12)
Randomly getting this as well ...
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 657, in init
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 716, in finish
self.wfile.close()
File "/usr/lib/python2.7/socket.py", line 279, in close
self.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
from broadlink-http-rest.
It looks to me like it can be a network issue..
from broadlink-http-rest.
@uudruid74 try with older broadlink module:
pip install -Iv broadlink==0.3
from broadlink-http-rest.
@radinsky - The network is working fine for everything else. And the web interface sending the AJAX request is running on the same physical server as the rest server. It's making a request to itself, so it shouldn't be a network problem.
@hackruu - Tried that and restarted the server, still no change. According to my waterfall diagram, the server takes about 20 seconds to respond for the initial request(s). Once it responds, it's fine (about 400ms response). Then it may randomly go to sleep again later. I'd say it was swapping but there is no swap configured (Beaglebone on Jessie).
from broadlink-http-rest.
I think the following is related ... https://stackoverflow.com/questions/10003866/http-server-hangs-while-accepting-packets
from broadlink-http-rest.
Adding timeout seems to help. the "nonblocking request" seems to block!
--- broadlink-http-rest-master/server.py 2017-08-10 10:30:09.000000000 -0500
+++ server.py 2018-03-22 18:23:15.353067594 -0500
@@ -8,6 +8,7 @@
from os import path
from Crypto.Cipher import AES
+address = "192.168.12.200"
class Server(BaseHTTPRequestHandler):
def _set_headers(self):
@@ -99,7 +100,7 @@
finalCommand = encodedCommand[0x04:]
signal.signal(signal.SIGALRM, signal_handler)
- signal.alarm(4) # Ten seconds
+ signal.alarm(2) # Two seconds
try:
device.send_data(finalCommand)
except Exception, msg:
@@ -178,9 +179,10 @@
print ("HTTP timeout, but the command should be already sent.")
-def start(server_class=HTTPServer, handler_class=Server, port=serverPort):
- server_address = ('', port)
+def start(server_class=HTTPServer, handler_class=Server, port=serverPort, timeout=1):
+ server_address = (address, port)
httpd = server_class(server_address, handler_class)
+ httpd.timeout = timeout
print 'Starting broadlink-rest server on port %s ...' % port
httpd.serve_forever()
@@ -222,4 +224,4 @@
else:
serverPort = 8080
- start(port=serverPort)
+ start(port=serverPort,timeout=RealTimeout)
from broadlink-http-rest.
@uudruid74, can you commit your changes? I will merge your patch, thanks!
from broadlink-http-rest.
@radinksky False alarm. It's dead again, keyboard interrupt still shows it hanging in the same "non blocking" call. I'll keep looking into this and will do a proper fork/PR when I have a system that turns on my TV in the morning without restarting the server first 😃
from broadlink-http-rest.
I'm testing more changes, and this time, I think I have it. Basically setting a timeout in the device itself. I did a bunch of changes and this needs time to test. There may still be a slight delay when its been left alone for awhile, but I'm pretty sure thats just the hard drive on my Beaglebone spinning down. It doesn't hang like it used to. PR coming soon
from broadlink-http-rest.
@radinsky I issued a PR. Really confident this is finally dead and can be closed
False alarm. It's still there. Hanging in the socket code. I'm not sure if there is a solution other than avoiding socket.py and writing our own.
from broadlink-http-rest.
OK. I managed to find out how to replicate. When a client rudely disconnects it seems to hang the server. So, while I'm testing it, all is good. I hibernate my laptop and no one can connect the next morning! Even a page refresh of my client was enough to trigger.
I solved it via adding socket timeouts to the server process and then gracefully closing the connection when the error propogates. Timeouts are configurable as "Timeout" in the global section, in tenths of a second, with a fast default. PR coming soon.
from broadlink-http-rest.
Aspect of single-threaded design, resolved via timeouts in #13
from broadlink-http-rest.
Related Issues (20)
- running issues
- Learn command problem HOT 3
- Unable to send commands HOT 4
- Interested in Advanced Features? HOT 2
- Where is the "learned code" saved? HOT 1
- Could you please provide an example of how to make a simple Macro Command? HOT 2
- 'module' object has no attribute 'SIGUSR1' HOT 2
- On/Off commands not sent HOT 5
- consecutive commands issue HOT 14
- RF does not receive and send HOT 18
- Duraflame?
- RM3 Mini support? HOT 4
- Send TV Channel Number HOT 4
- sendCommand not working after migration HOT 7
- AttributeError: rm instance has no attribute 'key' HOT 2
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 after a new learn HOT 5
- Copy an paste commands differnt devices HOT 3
- Sky Q Black HOT 2
- Is this offical? HOT 1
- NameError: name 'GlobalPassword' is not defined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from broadlink-http-rest.