Re: Why does 'connect' take so long (sometimes) and can't be interrupted?
On 6/15/17 11:36 AM, gaze...@xmission.com wrote: > 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. It's all system calls. If it hangs in `connect', bash has to wait until the system call returns one way or another. There is no provision for a timeout with connect, and any signal (e.g., SIGALRM) that bash tries to set for a timeout will be deferred until connect completes or fails anyway. > > 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 If that's a legit error, the problem might be with the server. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: Why does 'connect' take so long (sometimes) and can't be interrupted?
I can't think of what could cause this problem. The TCP connection code in Bash seems pretty straightforward, and in my experiments I was able to interrupt it even if it was waiting for the server to accept a connection, or waiting for an available slot in the listen queue. It's possible the problem is in your C code. Would you be able to post a version of it that exhibits the problem? - Original Message - From: gaze...@xmission.com To:Cc: Sent:Thu, 15 Jun 2017 09:36:12 -0600 Subject:Why does 'connect' take so long (sometimes) and can't be interrupted? 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.
Re: Why does 'connect' take so long (sometimes) and can't be interrupted?
On Thu, Jun 15, 2017 at 10:36 AM,wrote: [...] > 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 Attach to the hanged process with gdb, print a backtrace and reply back, so that we can see where it's stuck.
Why does 'connect' take so long (sometimes) and can't be interrupted?
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().