transientskp / aartfaac-control

AARTFAAC control scripts
0 stars 0 forks source link

cmdclient recv() extra characters after command #19

Closed hsuyeep closed 9 years ago

hsuyeep commented 9 years ago

cmdclient reports receiving sends() of 0 bytes after a legitimate command. The other side also breaks the connection uncleanly, leading to send () errors from cmdclient.

Sample cmdclient output (from the nohup fille--> [2015-07-06 22:29:40] Received connection from: ('10.149.96.3', 55060). --> [2015-07-06 22:29:40] Received: 0 STOP, len: 6. cmd: STOP <-- [2015-07-06 22:29:40] Terminating pid 22057. --> [2015-07-06 22:29:40] Received: 0 START --antpos=/usr/local/share/aartfaac/antennasets/lba_outer.dat --freq=54000000 --output=/data/atv --snapshot=/var/www/, len: 124. cmd: START <-- [2015-07-06 22:29:40] Running cmdstr: ['/home/prasad/aartfaac-tools/python/rtmon/atv.py', '--antpos=/usr/local/share/aartfaac/antennasets/lba_outer.dat', '--freq=54000000', '--output=/data/atv', '--snapshot=/var/www/']. <-- [2015-07-06 22:29:40] Successfully started pid 22168 for cmd execution, status: OK. --> [2015-07-06 22:29:40] Received: , len: 0.

Invalid command protocol! Try again.

--> [2015-07-06 22:29:40] Received: , len: 0.

Invalid command protocol! Try again.

--> [2015-07-06 22:29:40] Received: , len: 0.

Invalid command protocol! Try again.

--> [2015-07-06 22:29:40] Received: , len: 0.

Invalid command protocol! Try again.

Traceback (most recent call last): File "/home/prasad/aartfaac-control/clients/cmdclient.py", line 99, in threadhdlr self._servsock.send(self._status); socket.error: [Errno 32] Broken pipe /usr/lib/pymodules/python2.7/matplotlib/colors.py:533: RuntimeWarning: invalid value encountered in less cbook._putmask(xa, xa<0.0, -1) Unhandled exception in thread started by <bound method rtmonCmdClient.threadhdlr of <main.rtmonCmdClient object at 0x28bc350>> --> [2015-07-06 22:39:40] Received connection from: ('10.149.96.3', 59545).)

hsuyeep commented 9 years ago

Learnt that if the remote side starts closing down the connection, recv() returns with 0 length packets. The problem was solved by explicitly checking if the recv()ed packets were 0-length, then the current socket as generated by accept() is closed. The broken pipe was caused by cmdclient trying to send a status message over a socket which had been closed by the peer. Both problems have been resolved by this fix. Test: Can connect to a running cmdclient using nc: nc ais001 45000 0 STOP 0 STOP ^C The control-C breaks the connection, duplicating the above error. Now, no such error is reported.