title: infinite loop when receiving a large pickled object with sockets
body: <p>I'm using a remote linux server and I want to send an array via sockets from client with python so I used this code :</p>
  <pre><code>message = pickle.dumps(faceBlob)
  message_header = bytes(f&quot;{len(message):&lt;{HEADER_LENGTH}}&quot;, &quot;utf-8&quot;)
  client_socket.send(message_header + message)
  </code></pre>
  <p>to receive it in the server I used a while loop to catch all the message since it is &gt; 4096 :</p>
  <pre><code>def receive_blop(client_socket):
      # Receive our &quot;header&quot; containing message length, it's size is defined and constant
      message_header = client_socket.recv(HEADER_LENGTH)
  
      # If we received no data, client gracefully closed a connection, for example using socket.close() or socket.shutdown(socket.SHUT_RDWR)
      if not len(message_header):
          return False
  
      # Convert header to int value
      message_length = int(message_header.decode('utf-8').strip())
      fragments = []
      print(message_length)
  
      while True:
          # this loop is infinite
  
          print(&quot;I arrived her&quot;)
          chunk = client_socket.recv(4096)
          if not chunk:
              break
          fragments.append(chunk)
  
      data_arr = b&quot;&quot;.join(fragments)
  
  
      # Return an object of message header and message data
      return {'header': message_header, 'data': data_arr}
  </code></pre>
  <p>the server still printing the 'I arrived here' but receive the message until the connection is ended from the client</p>