I've tried to switch everything back to C library using popen and it
hanged too. In all places it hangs using pstream.h. Notice malformed
_IO_read_ptr. and all other pointers. It should look like " 9
10.13.19.18  4.762 ms  4.613 ms  4.158 ms\n", but there is "  4.613
ms.19.18  4.762 mss  3.658 ms  3.681 ms  3.144 ms0 byte packetsms".
Almost identical problem, just with totaly different approach. This
one worked for more than a year on tens of servers. No matter the
version of glibc. It happens with kernels 4.19 and 5.0. However I
didn't test older ones.

FILE* pipe = popen(command, "r");

if (!pipe)
{
    return false;
}

while (fgets(buffer.data(), sizeof(buffer), pipe) != NULL) // it
blocked here - #7 in backtrace
{
  returnSstream << buffer.data();
}

int processReturnValue = pclose(pipe);


gdb - output of pipe
+print *pipe
$1 = {_flags = -72539000, _IO_read_ptr = 0x7f22d006cca0 "  4.613
ms.19.18  4.762 mss  3.658 ms  3.681 ms  3.144 ms0 byte packetsms",
  _IO_read_end = 0x7f22d006cca0 "  4.613 ms.19.18  4.762 mss  3.658 ms
 3.681 ms  3.144 ms0 byte packetsms", _IO_read_base = 0x7f22d006cca0 "
 4.613 ms.19.18  4.762 mss  3.658 ms  3.681 ms  3.144 ms0 byte
packetsms",
  _IO_write_base = 0x7f22d006cca0 "  4.613 ms.19.18  4.762 mss  3.658
ms  3.681 ms  3.144 ms0 byte packetsms", _IO_write_ptr =
0x7f22d006cca0 "  4.613 ms.19.18  4.762 mss  3.658 ms  3.681 ms  3.144
ms0 byte packetsms",
  _IO_write_end = 0x7f22d006cca0 "  4.613 ms.19.18  4.762 mss  3.658
ms  3.681 ms  3.144 ms0 byte packetsms", _IO_buf_base = 0x7f22d006cca0
"  4.613 ms.19.18  4.762 mss  3.658 ms  3.681 ms  3.144 ms0 byte
packetsms",
  _IO_buf_end = 0x7f22d006dca0 "0W*\210hU", _IO_save_base = 0x0,
_IO_backup_base = 0x0, _IO_save_end = 0x0, _markers = 0x0, _chain =
0x7f23016c0680 <_IO_2_1_stderr_>, _fileno = 3, _flags2 = 128,
_old_offset = 5282249573778077746,
  _cur_column = 0, _vtable_offset = 14 '\016', _shortbuf = <incomplete
sequence \320>, _lock = 0x7f22d00e5590, _offset = -1, _codecvt =
0x756f72003234322e, _wide_data = 0xffffffffffffffff, _freeres_list =
0x0,
  _freeres_buf = 0x39312e33312e3031, __pad5 = 2333181267236106798,
_mode = -1, _unused2 =
"\"\177\000\000\f\000\000\000\000\000\000\000\061\060.13.19"}


gdb backtrace:
where
#0  __GI___libc_read (nbytes=4096, buf=0x7f22d006cca0, fd=3) at
../sysdeps/unix/sysv/linux/read.c:26
#1  __GI___libc_read (fd=3, buf=0x7f22d006cca0, nbytes=4096) at
../sysdeps/unix/sysv/linux/read.c:24
#2  0x00007f23015808e0 in _IO_new_file_underflow (fp=0x7f22d00e54a0)
at libioP.h:839
#3  0x00007f2301581a02 in __GI__IO_default_uflow (fp=0x7f22d00e54a0)
at libioP.h:839
#4  0x00007f23015751ba in __GI__IO_getline_info
(fp=fp@entry=0x7f22d00e54a0, buf=buf@entry=0x7f2300612160 " 9
10.13.19.18  4.762 ms  4.613 ms  4.158 ms\n", n=4060,
delim=delim@entry=10, extract_delim=extract_delim@entry=1,
    eof=eof@entry=0x0) at iogetline.c:60
#5  0x00007f23015752a8 in __GI__IO_getline
(fp=fp@entry=0x7f22d00e54a0, buf=buf@entry=0x7f2300612160 " 9
10.13.19.18  4.762 ms  4.613 ms  4.158 ms\n", n=<optimized out>,
delim=delim@entry=10, extract_delim=extract_delim@entry=1)
    at iogetline.c:34
#6  0x00007f230157425b in _IO_fgets (buf=0x7f2300612160 " 9
10.13.19.18  4.762 ms  4.613 ms  4.158 ms\n", n=<optimized out>,
fp=0x7f22d00e54a0) at iofgets.c:53
#7  0x00005568881d9b36 in Command::RunGetStringStream
(rCommandString="traceroute  -T  -n -q 3 -w 0.020000 10.13.19.193",
pCommandOutput=0x7f2300613380, logName="10.13.19.193") at
/root/shaperd/projects/lib/libCommand.cpp:1020
----
S pozdravem / Best Regards

Vaclav Zindulka

Reply via email to