llamaIndex - 💡(How to fix) Fix [Bug]: File handles not closed in HotpotQA evaluation benchmark [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

save_file = open(os.path.join(dataset_full_path, 'dev_distractor.json'), 'wb') response = requests.get(url, stream=True) for chunk in tqdm.tqdm(response.iter_content(chunk_size=chunk_size)): if chunk: save_file.write(chunk)

File never closed; if exception occurs, handle leaks

Fix Action

Fixed

Code Example

save_file = open(os.path.join(dataset_full_path, 'dev_distractor.json'), 'wb')
response = requests.get(url, stream=True)
for chunk in tqdm.tqdm(response.iter_content(chunk_size=chunk_size)):
    if chunk:
        save_file.write(chunk)
# File never closed; if exception occurs, handle leaks

---

f = open(dataset_path)
query_objects = json.loads(f.read())
# File never closed
RAW_BUFFERClick to expand / collapse

Bug Description

The HotpotQA evaluation benchmark has two file handle resource leaks that can exhaust file descriptors:

Issue 1: Download function (line 37)

save_file = open(os.path.join(dataset_full_path, 'dev_distractor.json'), 'wb')
response = requests.get(url, stream=True)
for chunk in tqdm.tqdm(response.iter_content(chunk_size=chunk_size)):
    if chunk:
        save_file.write(chunk)
# File never closed; if exception occurs, handle leaks

Issue 2: Run function (line 74)

f = open(dataset_path)
query_objects = json.loads(f.read())
# File never closed

Impact

  • File descriptor exhaustion if evaluation is run repeatedly
  • Memory leaks in long-running processes
  • Violates context manager best practices

Proposed Fix

  • Wrap file open calls in with statements
  • Issue 1: Add save_file.close() in finally block or use context manager
  • Issue 2: Replace with with open(dataset_path) as f:

File: llama-index-core/llama_index/core/evaluation/benchmarks/hotpotqa.py Lines: 37-50, 74-75

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

llamaIndex - 💡(How to fix) Fix [Bug]: File handles not closed in HotpotQA evaluation benchmark [2 pull requests]