A way to keep the TcpStream alive ? #6

Closed
opened 2022-09-15 11:53:48 +02:00 by rmanach · 3 comments
rmanach commented 2022-09-15 11:53:48 +02:00 (Migrated from gitea.thegux.fr)

In HTTP/1.1 (https://www.rfc-editor.org/rfc/rfc2616#section-8.1.2), the connection is automatically keeped alive.

This induce an error with python requests module :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/requests/api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

How to keep the connection alive ? Is this really useful for the need ?

In HTTP/1.1 (https://www.rfc-editor.org/rfc/rfc2616#section-8.1.2), the connection is automatically keeped alive. This induce an error with python requests module : ```log Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/requests/api.py", line 119, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) ``` How to keep the connection alive ? Is this really useful for the need ?
rmanach commented 2022-09-15 12:02:17 +02:00 (Migrated from gitea.thegux.fr)
tokio crate seems to implement this features: https://docs.rs/tokio/0.2.13/tokio/net/struct.TcpStream.html#method.set_keepalive
rmanach commented 2022-09-15 19:19:50 +02:00 (Migrated from gitea.thegux.fr)

related to : #5

related to : #5
rmanach commented 2022-09-19 17:00:25 +02:00 (Migrated from gitea.thegux.fr)

using tokio crate to handle async HTTP Request seems to resolve the issue. See tests in tests/python.

using `tokio` crate to handle async HTTP Request seems to resolve the issue. See tests in `tests/python`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rmanach/simple-auth#6