requests icon indicating copy to clipboard operation
requests copied to clipboard

requests.put() does not respect timeout when data is chunked

Open konlai opened this issue 2 years ago • 0 comments
trafficstars

requests.put(url, data=some_generator, timeout=5.0) does not timeout if the server accepts the connection but does not send a response.

Expected Result

requests.put(url, data=some_generator, timeout=5.0) would time out after 5 seconds if the server does not send a response.

Actual Result

requests.put(url, data=some_generator, timeout=5.0) can hang indefinitely if the server does not send a response and does not close the connection.

Reproduction Steps

import requests

def data_chunked():
    data = [b'hello', b'world']
    for chunk in data:
        yield chunk

# This can block forever if the server accepts the connection but does not respond
requests.put("http://localhost:8080/", data=data_chunked(), timeout=5.0)

# This times out as expected
requests.put("http://localhost:8080/", data=b'hello', timeout=5.0)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.10"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.3"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.8"
  },
  "platform": {
    "release": "3.10.0-1062.18.1.el7.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.27.1"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.26.8"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}

konlai avatar Nov 23 '22 06:11 konlai