Skip to content

Commit 3fd8a6e

Browse files
committed
fix: set sufficient buffer limit for idf.py confserver
1 parent 438e207 commit 3fd8a6e

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

tools/idf_py_actions/core_ext.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ def build_target(target_name: str, ctx: Context, args: PropertyDict) -> None:
5050
ensure_build_directory(args, ctx.info_name)
5151
run_target(target_name, args, force_progression=GENERATORS[args.generator].get('force_progression', False))
5252

53+
def confserver_target(target_name: str, ctx: Context, args: PropertyDict, buffer_size: int) -> None:
54+
"""
55+
Execute the idf.py confserver command with the specified buffer size.
56+
"""
57+
ensure_build_directory(args, ctx.info_name)
58+
if buffer_size < 2048:
59+
yellow_print(
60+
f'WARNING: The specified buffer size {buffer_size} KB is less than the '
61+
'recommended minimum of 2048 KB for idf.py confserver. Consider increasing it to at least 2048 KB '
62+
'by setting environment variable IDF_CONFSERVER_BUFFER_SIZE=<buffer size in KB> or by calling '
63+
'idf.py confserver --buffer-size <buffer size in KB>.'
64+
)
65+
try:
66+
run_target(
67+
target_name,
68+
args,
69+
force_progression=GENERATORS[args.generator].get('force_progression', False),
70+
buffer_size=buffer_size,
71+
)
72+
except ValueError as e:
73+
if str(e) == 'Separator is not found, and chunk exceed the limit':
74+
# Buffer size too small/one-line output of the command too long
75+
raise FatalError(
76+
f'ERROR: Command failed with an error message "{e}". '
77+
'Try increasing the buffer size to 2048 (or higher) by setting environment variable '
78+
'IDF_CONFSERVER_BUFFER_SIZE=<buffer size in KB> or by calling '
79+
'idf.py confserver --buffer-size <buffer size in KB>.'
80+
)
81+
else:
82+
raise
83+
5384
def size_target(
5485
target_name: str,
5586
ctx: Context,
@@ -520,9 +551,22 @@ def help_and_exit(action: str, ctx: Context, param: List, json_option: bool, add
520551
],
521552
},
522553
'confserver': {
523-
'callback': build_target,
554+
'callback': confserver_target,
524555
'help': 'Run JSON configuration server.',
525-
'options': global_options,
556+
'options': global_options
557+
+ [
558+
{
559+
'names': ['--buffer-size'],
560+
'help': (
561+
'Set the buffer size (in KB) in order to accommodate initial confserver response.'
562+
'Default value and recommended minimum is 2048 (KB), but it might need to be '
563+
'increased for very large projects.'
564+
),
565+
'type': int,
566+
'default': 2048,
567+
'envvar': 'IDF_CONFSERVER_BUFFER_SIZE',
568+
}
569+
],
526570
},
527571
'size': {
528572
'callback': size_target,

tools/idf_py_actions/tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def __init__(
303303
force_progression: bool = False,
304304
interactive: bool = False,
305305
convert_output: bool = False,
306+
buffer_size: Optional[int] = None,
306307
) -> None:
307308
self.tool_name = tool_name
308309
self.args = args
@@ -315,6 +316,7 @@ def __init__(
315316
self.force_progression = force_progression
316317
self.interactive = interactive
317318
self.convert_output = convert_output
319+
self.buffer_size = buffer_size or 256
318320

319321
def __call__(self) -> None:
320322
def quote_arg(arg: str) -> str:
@@ -373,7 +375,7 @@ async def run_command(self, cmd: List, env_copy: Dict) -> Tuple[Process, Optiona
373375
p = await asyncio.create_subprocess_exec(
374376
*cmd,
375377
env=env_copy,
376-
limit=1024 * 256,
378+
limit=1024 * self.buffer_size,
377379
cwd=self.cwd,
378380
stdout=asyncio.subprocess.PIPE,
379381
stderr=asyncio.subprocess.PIPE,
@@ -525,6 +527,7 @@ def run_target(
525527
custom_error_handler: Optional[FunctionType] = None,
526528
force_progression: bool = False,
527529
interactive: bool = False,
530+
buffer_size: Optional[int] = None,
528531
) -> None:
529532
"""Run target in build directory."""
530533
if env is None:
@@ -551,6 +554,7 @@ def run_target(
551554
hints=not args.no_hints,
552555
force_progression=force_progression,
553556
interactive=interactive,
557+
buffer_size=buffer_size,
554558
)()
555559

556560

0 commit comments

Comments
 (0)