ncとfifoの奇妙で一貫性のない出力

ncとfifoの奇妙で一貫性のない出力

私は次のような正確なコードを持っています:

#!/bin/bash

gtimeout(){
  if type -f gtimeout &> /dev/null; then
    command gtimeout "$@"
  else
    timeout "$@"
  fi
}

export -f gtimeout;


on_first_match(){
   local pattern="$1"  # The pattern to search for
    while IFS= read -r line; do
        if [[ "$line" == *"$pattern"* ]]; then
            exit 0
        fi
    done
}

export -f on_first_match


write_to_server(){
  echo -e "$?" | nc 0.0.0.0 3333
}

export -f write_to_server

(

set +e;
sleep 2;

  (
     gtimeout 15 docker logs -f rabbitmq-node1 | on_first_match 'Starting listener on';
     write_to_server
  ) &


  (
    gtimeout 15 docker logs -f mongodb-node1 | on_first_match 'waiting for connections';
    write_to_server
  ) &


  (
    gtimeout 15 docker logs -f elasticsearch-node1 | on_first_match 'started';
    write_to_server
  ) &


  (
     gtimeout 15 docker logs -f rabbitmq-node2 | on_first_match 'Starting listener on';
     write_to_server
  ) &


  (
    gtimeout 15 docker logs -f mongodb-node2 | on_first_match 'waiting for connections';
    write_to_server
  ) &


  (
    gtimeout 15 docker logs -f elasticsearch-node2 | on_first_match 'started';
    write_to_server
  ) &


  (
     gtimeout 15 docker logs -f rabbitmq-node3 | on_first_match 'Starting listener on';
     write_to_server
  ) &


  (
    gtimeout 15 docker logs -f mongodb-node3 | on_first_match 'waiting for connections';
    write_to_server
  ) &


  (
    gtimeout 15 docker logs -f elasticsearch-node3 | on_first_match 'started';
    write_to_server
  ) &


) &

gtimeout 30 nc -k -l 3333 | while IFS= read -r line; do
      echo "Received: $line";
done

私が得た結果は次のとおりです。

Error response from daemon: No such container: mongodb-node1
Error response from daemon: No such container: rabbitmq-node2
Error response from daemon: No such container: rabbitmq-node1
Error response from daemon: No such container: elasticsearch-node2
Error response from daemon: No such container: elasticsearch-node1
Error response from daemon: No such container: mongodb-node2
Error response from daemon: No such container: mongodb-node3
Error response from daemon: No such container: rabbitmq-node3
Error response from daemon: No such container: elasticsearch-node3
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0

(5行だけが受信され、時には4行、時には6行が受信されますが、予想どおり9行は受信されません)

しかし、私はこれを期待しています:

Error response from daemon: No such container: mongodb-node1
Error response from daemon: No such container: rabbitmq-node2
Error response from daemon: No such container: rabbitmq-node1
Error response from daemon: No such container: elasticsearch-node2
Error response from daemon: No such container: elasticsearch-node1
Error response from daemon: No such container: mongodb-node2
Error response from daemon: No such container: mongodb-node3
Error response from daemon: No such container: rabbitmq-node3
Error response from daemon: No such container: elasticsearch-node3
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0

9本の受信ラインがあります。

何が起こっているのか知っている人はいますか? (ソケットの代わりにmkfifoにコードを切り替えると同じ動作が発生します)。

関連情報