peerless1230 / xterm_django

基于xterm.js&websocket的Django Webssh 终端。(Webssh with xterm.js in django, data pass through websocket.)
Apache License 2.0
8 stars 0 forks source link

客户端调用ws.close(),报错 #1

Open wanggaolin opened 5 years ago

wanggaolin commented 5 years ago

Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 596, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 654, in init self.finish() File "/usr/lib/python2.7/SocketServer.py", line 713, in finish self.wfile.close() File "/usr/lib/python2.7/socket.py", line 283, in close self.flush() File "/usr/lib/python2.7/socket.py", line 307, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 9] Bad file descriptor

peerless1230 commented 5 years ago

你好 这个报错是因为django本身处理http连接请求时没有websocket的连接,我在http连接中嵌入了websocket连接,为了正常维护每次ssh连接的websocket句柄生命周期,只好在handle方法中显式close,而外层的http请求中的close后需要在handle方法执行完以后才会close。因此在websocket关闭到http连接关闭的中间窗口期,web客户端还可以在http连接中向websocket发数据,但实际已经关闭了,因此会在django的http连接中抛出异常,但这部分的异常没有其他影响