Repository: paperless-ngx/paperless-ngx

Issue:
Error while converting email to PDF: timed out
### Description

When I want to import a mail



### Steps to reproduce

Import a mail 

### Webserver logs

```bash
[2023-06-19 16:00:14,448] [ERROR] [paperless.consumer] Error while consuming document Re Briefkasten  boîte aux lettres.eml: Error while converting email to PDF: timed out
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/sync.py", line 28, in read
    return self._sock.recv(max_bytes)
socket.timeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 218, in handle_request
    resp = self._pool.handle_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/connection_pool.py", line 261, in handle_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/connection_pool.py", line 245, in handle_request
    response = connection.handle_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/connection.py", line 96, in handle_request
    return self._connection.handle_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/http11.py", line 120, in handle_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/http11.py", line 99, in handle_request
    ) = self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/http11.py", line 163, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_sync/http11.py", line 199, in _receive_event
    data = self._network_stream.read(
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/sync.py", line 28, in read
    return self._sock.recv(max_bytes)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/paperless/src/paperless_mail/parsers.py", line 329, in generate_pdf_from_mail
    response = httpx.post(
  File "/usr/local/lib/python3.9/site-packages/httpx/_api.py", line 304, in post
    return request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_api.py", line 100, in request
    return client.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 814, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 901, in send
    response = self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 218, in handle_request
    resp = self._pool.handle_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/paperless/src/documents/consumer.py", line 382, in try_consume_file
    document_parser.parse(self.path, mime_type, self.filename)
  File "/usr/src/paperless/src/paperless_mail/parsers.py", line 147, in parse
    self.archive_path = self.generate_pdf(mail)
  File "/usr/src/paperless/src/paperless_mail/parsers.py", line 187, in generate_pdf
    mail_pdf_file = self.generate_pdf_from_mail(mail_message)
  File "/usr/src/paperless/src/paperless_mail/parsers.py", line 337, in generate_pdf_from_mail
    raise ParseError(
documents.parsers.ParseError: Error while converting email to PDF: timed out
```


### Browser logs

_No response_

### Paperless-ngx version

1.16.1

### Host OS

Docker Synology NAS 

### Installation method

Docker - official image

### Browser

Safari

### Configuration changes

_No response_

### Other

_No response_


Discussion:
Is a Synology kind of low powered hardware?
I have a DS920+ and so far this has worked great and only the Paperless Container is running on it. 
That doesn't really answer the question, but I'll just make the timeout longer when I can.  I'm assuming it's somewhat underpowered and just takes more time to do the conversion.
Thanks for your quick help 
where can I set the timeout ? 

Resolving patch:
diff --git a/src/paperless_mail/parsers.py b/src/paperless_mail/parsers.py
--- a/src/paperless_mail/parsers.py
+++ b/src/paperless_mail/parsers.py
@@ -218,7 +218,7 @@ def generate_pdf(self, mail_message: MailMessage) -> Path:
                         file_multi_part[2],
                     )
 
-                response = httpx.post(url_merge, files=pdf_collection)
+                response = httpx.post(url_merge, files=pdf_collection, timeout=30.0)
                 response.raise_for_status()  # ensure we notice bad responses
 
                 archive_path.write_bytes(response.content)
@@ -336,6 +336,7 @@ def generate_pdf_from_mail(self, mail: MailMessage) -> Path:
                     files=files,
                     headers=headers,
                     data=data,
+                    timeout=30.0,
                 )
                 response.raise_for_status()  # ensure we notice bad responses
             except Exception as err:
@@ -414,11 +415,7 @@ def clean_html_script(text: str):
                     file_multi_part[2],
                 )
 
-            response = httpx.post(
-                url,
-                files=files,
-                data=data,
-            )
+            response = httpx.post(url, files=files, data=data, timeout=30.0)
             response.raise_for_status()  # ensure we notice bad responses
         except Exception as err:
             raise ParseError(f"Error while converting document to PDF: {err}") from err
diff --git a/src/paperless_tika/parsers.py b/src/paperless_tika/parsers.py
--- a/src/paperless_tika/parsers.py
+++ b/src/paperless_tika/parsers.py
@@ -96,7 +96,13 @@ def convert_to_pdf(self, document_path, file_name):
                 data["pdfFormat"] = "PDF/A-3b"
 
             try:
-                response = httpx.post(url, files=files, headers=headers, data=data)
+                response = httpx.post(
+                    url,
+                    files=files,
+                    headers=headers,
+                    data=data,
+                    timeout=30.0,
+                )
                 response.raise_for_status()  # ensure we notice bad responses
             except Exception as err:
                 raise ParseError(


Test patch: