summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2016-05-28 11:07:44 -0600
committerAaron Ball <nullspoon@iohq.net>2016-05-28 11:15:22 -0600
commitc36103d9dfcca11f75a568d5ab9569e28ba35d1e (patch)
tree1966680754c7303115ef4d862cc692827ccaa843
parenta0efae77e4b573864011edbcbee61cb85c82d343 (diff)
downloadircmsg-master.tar.gz
ircmsg-master.tar.xz
Put in msg timeout waiting for ping responseHEADmaster
Before, occasionally, the server would not respond (usually due to connection flood when used with a scheduler) with a ping response. This caused the get_ping function to infinitely loop, very quickly, causing the cpu to spike and the process to never exit. This commit fixes that behavior by looping no more than 50 times with an empty response before exiting. Also added a "no ping response received" error message to better explain when exiting with failure in this scenario.
-rwxr-xr-xircmsg.sh17
1 files changed, 16 insertions, 1 deletions
diff --git a/ircmsg.sh b/ircmsg.sh
index 754d736..a504466 100755
--- a/ircmsg.sh
+++ b/ircmsg.sh
@@ -24,12 +24,22 @@ portfd=''
# matching "PING". Retrieves value of that line (without the PING prefix), and
# returns so the corresponding PONG can be sent.
#
+# Note: This function will timeout when reading from the server 100 times
+#
function get_ping {
local portfd=${1}
+ local emptymax=50
+ local emptycount=0
# get ping
- while [[ ${ping:0:4} != 'PING' ]]; do
+ while [[ ${emptycount} -lt ${emptymax} ]]; do
read ping <&${portfd}
+
+ # If first four match PING, break and process
+ [[ ${ping:0:4} == 'PING' ]] && break
+
+ # If response is empty, increment empty counter
+ [[ ${ping} == '' ]] && emptycount=$(($emptycount + 1))
done
ping=${ping:5}
@@ -87,6 +97,11 @@ function main {
# Respond to the server with its ping value (ping pong)
ping=$(get_ping ${portfd})
+ if [[ ${ping} == '' ]]; then
+ echo "ERROR: No PING response received. Cannot continue."
+ exit 1
+ fi
+
echo "PONG ${ping}" >&${portfd}
# Send message to specified channel

Generated by cgit