title: HTTPoison post request Timeouts Eixir
body: <p>We are using a filesystem written in Go, <a href="https://github.com/chrislusf/seaweedfs" rel="nofollow noreferrer">seaweedfs</a>. It's being used a REST API on port 8888 to post Files. The issue we are having is <code>HTTPoison</code> timeouts.</p>
  
  <p>We post to a file, again and again, we get HTTPoison request timeout.</p>
  
  <p>Few facts:</p>
  
  <ul>
  <li>File do get updated on seaweedfs we can see the modified date.</li>
  <li>HTTPoison request response is always timeout</li>
  <li>I have tried with curl POST. <code>for ((i=1;i&lt;=100;i++)); do curl -F file=@00_13_000.jpg -X POST http://188.xx.xx.xx.217:8888/everc-dupzo/snapshots/recordings/2019/11/22/09/00_13_000.jpg; done</code> which works fine without any timeout.</li>
  <li>I have also tried to do it in my local machine with HTTPoison as well but it works fine.</li>
  </ul>
  
  <p><strong>Production</strong></p>
  
  <p>In production, we are sending almost 1K POST <code>HTTPoison</code> requests from which 10% gives timeout error. mostly on such files which are already present. they do get updated but HTTPoison request comes as a timeout.</p>
  
  <p>The code we are using to do POST request is written as under.</p>
  
  <pre><code>  def seaweedfs_save(camera_exid, timestamp, image, _notes) do
      [{_, _, _, _, [server]}] = :ets.match_object(:storage_servers, {:_, "RW", :_, :_, :_})
      hackney = [pool: :seaweedfs_upload_pool]
      directory_path = construct_directory_path(camera_exid, timestamp, "recordings", "")
      file_name = construct_file_name(timestamp)
      file_path = directory_path &lt;&gt; file_name
      case HTTPoison.post("#{server.url}#{file_path}", {:multipart, [{file_path, image, []}]}, [], hackney: hackney) do
        {:ok, response} -&gt; response
        {:error, error} -&gt; Logger.info "[seaweedfs_save] [#{file_path}] [#{camera_exid}] [#{inspect error}]"
      end
    end
  </code></pre>
  
  <p>hackney pool is set to</p>
  
  <pre><code>:hackney_pool.child_spec(:seaweedfs_upload_pool, [timeout: 5000, max_connections: 1000])
  </code></pre>
  
  <p>The author of seaweedfs has a hunch that HTTPoison requests are not getting closed or being reused.
  The author of Hackney suggests: </p>
  
  <blockquote>
    <p>http is a request/response protocol so unless a response is not
    supposed to have a body (204, 304, head) hackney will wait for it
    until you pass the skip_body option, with_body option or if none of
    them is passed will wait until it timeout</p>
  </blockquote>
  
  <p>But HTTPoison don't allow it <a href="https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L812" rel="nofollow noreferrer">https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L812</a></p>
  
  <p>I am at quite a dead end with it. Any help would be thankful about</p>
  
  <ol>
  <li>How should we do HHTPoison request?</li>
  <li>Should we just switch to Hackney?</li>
  <li>Or is there any better way to solve this problem? or any way to get more information about why a request is being timed out?</li>
  </ol>