-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(grep): raise asyncio stream limit and catch ValueError on long lines #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,7 @@ async def _rg_grep( | |
| cwd=str(root), | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| limit=8 * 1024 * 1024, # 8 MB per line — avoids LimitOverrunError on long lines | ||
| ) | ||
|
|
||
| matches: list[str] = [] | ||
|
|
@@ -239,6 +240,7 @@ async def _rg_grep_file( | |
| cwd=str(path.parent), | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| limit=8 * 1024 * 1024, # 8 MB per line — avoids LimitOverrunError on long lines | ||
| ) | ||
|
Comment on lines
240
to
244
|
||
|
|
||
| matches: list[str] = [] | ||
|
|
@@ -282,7 +284,11 @@ async def _collect_rg_matches( | |
| ) -> None: | ||
| assert process.stdout is not None | ||
| while len(matches) < limit: | ||
| raw = await process.stdout.readline() | ||
| try: | ||
| raw = await process.stdout.readline() | ||
| except ValueError: | ||
| # Line exceeded the stream buffer limit; skip it and continue. | ||
| continue | ||
|
Comment on lines
+287
to
+291
|
||
| if not raw: | ||
| break | ||
| line = raw.decode("utf-8", errors="replace").rstrip("\n") | ||
|
|
@@ -300,7 +306,11 @@ async def _collect_rg_file_matches( | |
| ) -> None: | ||
| assert process.stdout is not None | ||
| while len(matches) < limit: | ||
| raw = await process.stdout.readline() | ||
| try: | ||
| raw = await process.stdout.readline() | ||
| except ValueError: | ||
| # Line exceeded the stream buffer limit; skip it and continue. | ||
| continue | ||
|
Comment on lines
+309
to
+313
|
||
| if not raw: | ||
| break | ||
| line = raw.decode("utf-8", errors="replace").rstrip("\n") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 8 MB stream limit value is duplicated here and in
_rg_grep_file. Consider extracting it into a module-level constant (e.g.,_RG_STREAM_LIMIT_BYTES) so it’s easy to tune and avoids the two call sites drifting over time.