Skip to content

Commit 9a8961f

Browse files
committed
tools: add a custom timeout of 5s for the network using command git -C . fetch V_REPO in v doctor (it normally takes <1s) (fix #23955)
1 parent 7c42822 commit 9a8961f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cmd/tools/vdoctor.v

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct App {
99
mut:
1010
report_lines []string
1111
cached_cpuinfo map[string]string
12+
vexe string
1213
}
1314

1415
fn (mut a App) println(s string) {
@@ -112,11 +113,11 @@ fn (mut a App) collect_info() {
112113
}
113114

114115
a.line('', '')
115-
mut vexe := os.getenv('VEXE')
116-
mut vroot := os.dir(vexe)
117-
mut vmodules := os.vmodules_dir()
118-
mut vtmp_dir := os.vtmp_dir()
119-
mut getwd := os.getwd()
116+
vexe := a.vexe
117+
vroot := os.dir(vexe)
118+
vmodules := os.vmodules_dir()
119+
vtmp_dir := os.vtmp_dir()
120+
getwd := os.getwd()
120121
os.chdir(vroot) or {}
121122
a.line('V executable', vexe)
122123
a.line('V last modified time', time.unix(os.file_last_mod_unix(vexe)).str())
@@ -262,7 +263,7 @@ fn (mut a App) cpu_info(key string) string {
262263
fn (mut a App) git_info() string {
263264
mut out := a.cmd(command: 'git -C . describe --abbrev=8 --dirty --always --tags').trim_space()
264265
os.execute('git -C . remote add V_REPO https://github.com/vlang/v') // ignore failure (i.e. remote exists)
265-
os.execute('git -C . fetch V_REPO')
266+
os.execute('${os.quoted_path(a.vexe)} timeout 5.1 "git -C . fetch V_REPO"') // usually takes ~0.6s; 5 seconds should be enough for even the slowest networks
266267
commit_count := a.cmd(command: 'git rev-list @{0}...V_REPO/master --right-only --count').int()
267268
if commit_count > 0 {
268269
out += ' (${commit_count} commit(s) behind V master)'
@@ -322,6 +323,7 @@ fn diagnose_dir(path string) string {
322323

323324
fn main() {
324325
mut app := App{}
326+
app.vexe = os.getenv('VEXE')
325327
app.collect_info()
326328
app.report_info()
327329
}

0 commit comments

Comments
 (0)