salt icon indicating copy to clipboard operation
salt copied to clipboard

salt minion startup failed when there are too many connections.

Open guozequn opened this issue 9 years ago • 11 comments

Description of Issue/Question

I found there are serveral minions startup failed and the script always stucked:

[root@basic ~]# sh -x /etc/init.d/salt-minion start
+ : /usr/bin
+ : /etc
+ : root
+ SALTMINION=/usr/bin/salt-minion
+ SALTCALL=/usr/bin/salt-call
+ : '
root /etc/salt
'
+ SALTMINION_ARGS=
+ SALTMINION_TIMEOUT=30
+ SALTMINION_TICK=1
+ SERVICE=salt-minion
+ '[' -f /etc/default/salt ']'
+ '[' -f /etc/sysconfig/salt ']'
+ RETVAL=0
+ NS_NOTRIM=--notrim
+ ERROR_TO_DEVNULL=/dev/null
+ '[' 1 = 0 ']'
+ main start
+ '[' -n '' ']'
+ netstat --notrim -n
+ grep -q unrecognized
^C

there is no response when the script executing this commands:

if netstat --notrim -n 2>&1 >/dev/null | grep -q 'unrecognized'; then
    NS_NOTRIM=''
fi

all of these servers exist more than 250k persistent connetions, the server prints an endless ouput when i execute netstat -n , so i think this may be the reason why script always blocked.

[root@basic ~]# ss -o state established |wc -l
277797

Versions Report

salt-minion 2016.11.5 (Carbon)

guozequn avatar May 26 '17 10:05 guozequn

@dmurphy18 any opinions on this to change this command to something else to determine if no-trim is available. Is it possible to use netstat without listing out connections?

Ch3LL avatar May 26 '17 19:05 Ch3LL

@Ch3LL @guozequn Would need more information as to OS running on, memory size etc. Please get the full versions report by running salt-run --versions-report

Also can you please attach the appropriate portion of the script, if that is possible.

Thanks

dmurphy18 avatar May 30 '17 20:05 dmurphy18

Memory size

[root@basic ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         15949      14259       1689          1        114       4590
-/+ buffers/cache:       9554       6394
Swap:         6193       1671       4522

This is the time while exec netstat -n costs:

[root@basic ~]# time netstat -n > /dev/null

real	6m3.266s
user	0m4.067s
sys	5m41.573s

/etc/init.d/salt-minion start takes too much time when then the main function checking if --notrim is a valid netstat option.

main() {
    if [ -n "$SALTMINION_DEBUG" ]; then
        set -x
        ERROR_TO_DEVNULL="&2"
    fi

    # Check to see if --notrim is a valid netstat option

    if
        netstat --notrim -n 2>&1 >/dev/null | grep -q 'unrecognized'; then
        NS_NOTRIM=''
    fi
        
    # Pre-filter for unhandled commands
    case "$1" in
        (start|stop|status|restart|condrestart|try-restart) ;;
        (reload)
            echo "Can't reload $SERVICE - you must restart it"
            exit 3
            ;;
        (*)
            echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
            exit 2
            ;;
    esac

    while read MINION_USER CONFIG_DIR; do
        if [ -z "$CONFIG_DIR" ]; then
            continue
        fi

        if ! [ -d "$CONFIG_DIR" ]; then
            echo "ERROR: non-existent $SERVICE config directory: $CONFIG_DIR"
            RETVAL=1
            continue
        fi

        SOCK_DIR="$(_get_salt_config_value sock_dir)"
        PID_FILE="$(_get_salt_config_value pidfile)"
        LOG_FILE="$(_get_salt_config_value log_file)"
        MINION_ID="$(_get_salt_config_value id)"
        MINION_ID_HASH="$(_make_id_hash "$MINION_ID")"
        if [ \
            -z "$SOCK_DIR" \
            -o -z "$PID_FILE" \
            -o -z "$LOG_FILE" \
            -o -z "$MINION_ID" \
            -o -z "$MINION_ID_HASH" \
        ]; then
            echo "ERROR: Unable to look-up config values for $CONFIG_DIR"
            RETVAL=1
            continue
        fi

        # See how we were called.
        case "$1" in
            (start|stop|restart|status)
                "$1" || RETVAL=$?
                ;;
            (condrestart|try-restart)
                if ! _is_running; then
                    RETVAL=7
                else
                    stop
                    start || RETVAL=$?
                fi
                ;;
            (*)
                echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
                RETVAL=2
                ;;
        esac
    done <<EOF
$SALTMINION_CONFIGS
EOF

    exit $RETVAL
}

I temporarily use these to instead of the previous part, and the problem seems to be solved.

   # Check to see if --notrim is a valid netstat option
    if
        ! netstat --help 2>&1 |grep -q "\-\-notrim"; then
        NS_NOTRIM=''
    fi

Versions Report

[root@basic ~]# salt-minion --versions-report
Salt Version:
           Salt: 2016.11.5
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.6.0
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: 3.4.3
         pygit2: Not Installed
         Python: 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
 
System Versions:
           dist: centos 6.6 Final
        machine: x86_64
        release: 2.6.32-926.504.30.3.letv.el6.x86_64
         system: Linux
        version: CentOS 6.6 Final

guozequn avatar May 31 '17 07:05 guozequn

@guozequn Wonder why the command 'time netstat -n > /dev/null' is taking minutes. Running the same command on a Redhat 6.9 system resulted in significantly quicker times, for example:

root@tc6min:~# time netstat -n > /dev/null

real 0m0.006s user 0m0.000s sys 0m0.004s root@tc6min:~# cat /etc/redhat-release CentOS release 6.9 (Final) root@tc6min:~#

Also I would expect to use 'service salt-minion restart' rather than the direct /etc/init.d/salt-minion start.

dmurphy18 avatar May 31 '17 16:05 dmurphy18

@dmurphy18 Large number of persistent connections established on these servers, and 'netstat -n' takes several minutes to print the outputs.

the count of established connections: image time costs of 'netstat -n': image server loads: image

guozequn avatar Jun 01 '17 10:06 guozequn

@guozequn Can you try replacing the lines in the script containing:

if
    netstat --notrim -n 2>&1 >/dev/null | grep -q 'unrecognized'; then
    NS_NOTRIM=''
fi

with: if ! ( netstat --help 2>&1 | grep -wq '--notrim') ; then NS_NOTRIM='' fi

And let me know if this resolves the issue, with checking if the option '--notrim' exists takes too long.

dmurphy18 avatar Jun 01 '17 17:06 dmurphy18

image

@dmurphy18 the time has been reduced from 10+ munites to 1 minute.

guozequn avatar Jun 02 '17 03:06 guozequn

@guozequn Has the change resolved the issue you saw where salt minion startup fails when there are too many connections ?

dmurphy18 avatar Jun 02 '17 16:06 dmurphy18

@dmurphy18 yes , Thank you.

guozequn avatar Jun 03 '17 09:06 guozequn

@guozequn Thanks for that information. I shall update the init scripts so that this problem is resolved in the next point releases.

dmurphy18 avatar Jun 05 '17 17:06 dmurphy18

Fixed with #41639

rallytime avatar Jun 07 '17 23:06 rallytime