Skip to content
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

[os] set_redirect_stdio() cause process hang when child process output large text #23990

Closed
kbkpbot opened this issue Mar 20, 2025 · 3 comments
Closed
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@kbkpbot
Copy link
Contributor

kbkpbot commented Mar 20, 2025

Describe the bug

When try to use set_redirect_stdio() get the output of a child process, it will hang when child process try to output large text.

Reproduction Steps

create two file:

sub.v

module main
fn main() {
        // Windows' limit is 4095
        // Linux's limit is 65535
	x := '1'.repeat(65536)    // change to 65535 will not hang under Linux
	println(x)
}

pp.v

module main
import os

fn main() {
	mut p := os.new_process('./sub')
	p.set_redirect_stdio()
	p.wait()
	assert p.code == 0
	output := p.stdout_slurp().trim_space()
	p.close()
	dump(output)
}

then compile files:

v sub.v
v pp.v

run pp

./pp

Expected Behavior

dump the output child:

1111111111111111111111111111111111111111111111....11111

Current Behavior

run ./pp will just hang.

Possible Solution

modify repeat() to a smaller number.
Maybe use a separate thread read the stdout/stderr, before we wait the child finish.

Additional Information/Context

V version

V 0.4.10 21874f9.a9a96b8

Environment details (OS name and version, etc.)

V full version V 0.4.10 21874f9.a9a96b8
OS windows, Microsoft Windows 10 企业版 LTSC 19044 64 位
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 7840H with Radeon 780M Graphics
Memory 1.32GB/27.69GB
V executable D:\v\v\v\v.exe
V last modified time 2025-03-20 13:20:58
V home dir OK, value: D:\v\v\v
VMODULES OK, value: C:\Users\DDT.vmodules
VTMP OK, value: C:\Users\DDT\AppData\Local\Temp\v_0
Current working dir OK, value: D:\v\bug\process
Git version git version 2.43.0.windows.1
V git status 0.4.10-1-ga9a96b89-dirty
.git/config present true
cc version N/A
gcc version N/A
clang version N/A
msvc version 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.39.33523 版
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version N/A
glibc version N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@kbkpbot kbkpbot added the Bug This tag is applied to issues which reports bugs. label Mar 20, 2025
Copy link

Connected to Huly®: V_0.6-22383

@kbkpbot kbkpbot changed the title [os] set_redirect_stdio() cause process hang under Windows [os] set_redirect_stdio() cause process hang when child process output large text Mar 20, 2025
@phcreery
Copy link
Contributor

Similar: vlang/v-analyzer#130

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Mar 21, 2025

This can be solved by std_read() before process end:

module main
import os

fn main() {
	mut output := ''
	mut p := os.new_process('./sub.exe')
	p.set_redirect_stdio()
	p.run()
	for p.is_alive() {
		output += p.stdout_read()
	}
	p.wait()
	output += p.stdout_read()
	assert p.code == 0
	p.close()
	dump(output.len)
}

But for windows, it need to implement the function is_pending().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants