Skip to content

Commit e4eb95e

Browse files
authored
Warn when consolidating citations with a low timeout (#113)
Citation consolidation makes GROBID query external services and is much slower than a plain extraction; a low client-side timeout frequently results in HTTP 408 (Request Timeout) errors. Emit a warning when consolidation is enabled with a timeout below 120s and document the recommended value in the Readme. Closes #54
1 parent f4f70d6 commit e4eb95e

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ settings.
298298
> Since version 0.0.12, the config file is optional. The client will use default localhost settings if no configuration
299299
> is provided.
300300
301+
> [!WARNING]
302+
> **Citation consolidation and the `timeout` setting.** When `--consolidate_citations` (or `consolidate_citations=True`)
303+
> is enabled, GROBID queries external services (e.g. CrossRef) to enrich the extracted references. This is considerably
304+
> slower than a plain extraction, and a low `timeout` frequently causes `HTTP 408 (Request Timeout)` errors.
305+
> Set the `timeout` to at least **120 seconds (2-3 minutes recommended)** when consolidating citations. The client emits
306+
> a warning when consolidation is requested with a timeout below 120 seconds.
307+
> See [issue #54](https://github.com/grobidOrg/grobid-client-python/issues/54).
308+
301309
### Logging Configuration
302310

303311
The client provides configurable logging with different verbosity levels. By default, only essential statistics and warnings are shown.

grobid_client/grobid_client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def __init__(self, message="GROBID server is not available"):
4040

4141

4242
class GrobidClient(ApiClient):
43+
# Below this client-side timeout (in seconds) citation consolidation is
44+
# likely to trigger HTTP 408 (Request Timeout) errors, so we warn the user.
45+
# See https://github.com/grobidOrg/grobid-client-python/issues/54
46+
CONSOLIDATE_CITATIONS_MIN_TIMEOUT = 120
47+
4348
# Default configuration values
4449
DEFAULT_CONFIG = {
4550
'grobid_server': 'http://localhost:8070',
@@ -113,6 +118,27 @@ def _set_config_params(self, params):
113118
if value is not None:
114119
self.config[key] = value
115120

121+
def _warn_on_consolidation_timeout(self, consolidate_citations):
122+
"""Warn when citation consolidation is enabled with a low client timeout.
123+
124+
Consolidating citations makes GROBID query external services and can be
125+
much slower than a plain extraction. A short client-side timeout often
126+
leads to HTTP 408 errors, so we recommend at least a couple of minutes.
127+
See https://github.com/grobidOrg/grobid-client-python/issues/54
128+
"""
129+
if not consolidate_citations:
130+
return
131+
132+
timeout = self.config.get("timeout", self.DEFAULT_CONFIG["timeout"])
133+
if timeout < self.CONSOLIDATE_CITATIONS_MIN_TIMEOUT:
134+
self.logger.warning(
135+
f"Citation consolidation is enabled but the timeout is only {timeout}s. "
136+
f"Consolidation queries external services and can be slow; a low timeout "
137+
f"frequently causes HTTP 408 (Request Timeout) errors. Consider increasing "
138+
f"the 'timeout' setting to at least {self.CONSOLIDATE_CITATIONS_MIN_TIMEOUT}s "
139+
f"(2-3 minutes is recommended)."
140+
)
141+
116142
def _handle_server_busy_retry(self, file_path, retry_func, *args, **kwargs):
117143
"""Handle server busy (503) retry logic."""
118144
self.logger.warning(f"Server busy (503), retrying {file_path} after {self.config['sleep_time']} seconds")
@@ -345,6 +371,13 @@ def process(
345371
start_time = time.time()
346372
batch_size_pdf = self.config["batch_size"]
347373

374+
# Warn if citation consolidation is requested with a short timeout: the
375+
# consolidation step queries external services (e.g. CrossRef) and can
376+
# be significantly slower, frequently resulting in HTTP 408 errors when
377+
# the client-side timeout is too low.
378+
# See https://github.com/grobidOrg/grobid-client-python/issues/54
379+
self._warn_on_consolidation_timeout(consolidate_citations)
380+
348381
# First pass: count all eligible files
349382
all_input_files = []
350383
for (dirpath, dirnames, filenames) in os.walk(input_path):

0 commit comments

Comments
 (0)