launch icon indicating copy to clipboard operation
launch copied to clipboard

Avoid too many characters cached in buffer

Open huweiATgithub opened this issue 1 year ago • 1 comments

Issue Description

Recently, I've encountered an issue that the launch test (added with add_ros_test with a launch.py file) hangs indefinitely. After investigation, I found that it was stuck at the getvalue call of a StringIO buffer: https://github.com/ros2/launch/blob/f3e9cfebcfa75c82299bb31674355a29454489fa/launch/launch/actions/execute_local.py#L391-L396

The root cause is that the __on_process_output method stores output in the buffer but does not process it, resulting in a huge buffer to be getvalue on (and thus hangs): https://github.com/ros2/launch/blob/f3e9cfebcfa75c82299bb31674355a29454489fa/launch/launch/actions/execute_local.py#L378-L385

This happens because one of my noisy program prints to stdout without a line separator, causing the buffer to accumulate.

Proposed Improvement

This PR addresses the issue by ensuring the buffer does not store too many characters, which I think it is always not wrong.

Other Changes

  1. I also change the os.linesep to \n since from the doc of StringIO, the StringIO by default uses \n as newline. Otherwise, writing lines with EOL='\n' in Windows will stop line from being processed.
  2. Remove the break in the else clause; this is unnecessary, it will be the last line in the buffer if it does not end with the line separator.

huweiATgithub avatar Sep 26 '24 15:09 huweiATgithub

@mjcarroll can you assign yourself to this? (i do not have power...)

fujitatomoya avatar Oct 04 '24 04:10 fujitatomoya