bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why does 'connect' take so long (sometimes) and can't be interrupted?


From: gazelle
Subject: Why does 'connect' take so long (sometimes) and can't be interrupted?
Date: Thu, 15 Jun 2017 09:36:12 -0600

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/.../local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2 
-Wno-parentheses -Wno-format-security
uname output: Linux shell 4.4.0-79-generic #100-Ubuntu SMP Wed May 17 19:58:14 
UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.4
Patch Level: 0
Release Status: release

Description:
        This is a little complicated and I can't give you full details on how to
        replicate it, since I don't fully understand it myself.  But under 
certain
        circumstances, the following line takes a very long time to execute:

            exec 5<>/dev/tcp/localhost/12345

        My objections are twofold:
            a) That it takes so long - it should either succeed or file (almost)
                immediately.
            b) When it is running, it is uninterruptable.  None of ^C, ^\, or 
^Z, nor
                any signal sent to the bash process (other than SIGKILL) will 
cause
                it to exit.  Effectively, the only escape is to SIGKILL the bash
                process, which causes the entire shell to be killed.

        More details below.

Repeat-By:
        I am using a bash script to communicate with a program that I wrote (in 
C)
        using TCPIP.  The C program listens on port 12345 (for example) and the 
bash
        script connects to it, using the command line shown above.  The actual 
lines
        in my script are now as follows:

            printf "Elapsed time for this 'exec' ...\t";tme=$(date +%s)
            exec 5<>/dev/tcp/localhost/12345
            echo "$(($(date +%s) - $tme)) seconds."

        Normally, for almost all possible inputs (to the C program), this 
executes
        immediately (says "0 seconds" elapsed).  But, for one particular input, 
it
        takes a very long time - in my most recent test, it was 116 seconds (!).
        This problem is 100% repeatable (with the given specific input to the C
        program).

        Note, however, that it does eventually connect.  As far as I can tell, 
it
        does always eventually connect.

        Needless to say, when I first hit this problem, I assumed it had hung, 
and
        when I tried to kill it, I ran into the problems described above.

        Also note: In testing this, I found that if I do hit ^C while it is 
hung,
        then wait long enough, eventually it does exit as shown below:

Elapsed time for this 'exec' ...        ^C^C^C^Cbash: connect: Connection 
refused
bash: /dev/tcp/localhost/12345: Connection refused

Fix:
        Well, I'd like to know why it (sometimes) takes so long.
        Amd it would be nice if you could interrupt it when it does hang.
        Or, alternatively, set a timelimit for the connect().




reply via email to

[Prev in Thread] Current Thread [Next in Thread]