Skip to content

Commit c71c75e

Browse files
authored
Merge pull request #1247 from pborzenkov/close-race
job: fix race between channel close and job exit
2 parents 48e0660 + 5c721a2 commit c71c75e

File tree

7 files changed

+28
-59
lines changed

7 files changed

+28
-59
lines changed

autoload/go/cmd.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ function s:cmd_job(args) abort
445445

446446
let start_options = {
447447
\ 'callback': callbacks.callback,
448-
\ 'close_cb': callbacks.close_cb,
448+
\ 'exit_cb': callbacks.exit_cb,
449449
\ }
450450

451451
" modify GOPATH if needed

autoload/go/coverage.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function s:coverage_job(args)
288288

289289
let start_options = {
290290
\ 'callback': callbacks.callback,
291-
\ 'close_cb': callbacks.close_cb,
291+
\ 'exit_cb': callbacks.exit_cb,
292292
\ }
293293

294294
" modify GOPATH if needed

autoload/go/def.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function s:def_job(args) abort
303303

304304
let start_options = {
305305
\ 'callback': callbacks.callback,
306-
\ 'close_cb': callbacks.close_cb,
306+
\ 'exit_cb': callbacks.exit_cb,
307307
\ }
308308

309309
if &modified

autoload/go/guru.vim

+10-18
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,12 @@ function! s:async_guru(args) abort
155155
endif
156156
endif
157157

158-
function! s:close_cb(chan) closure
159-
let messages = []
160-
while ch_status(a:chan, {'part': 'out'}) == 'buffered'
161-
let msg = ch_read(a:chan, {'part': 'out'})
162-
call add(messages, msg)
163-
endwhile
164-
165-
while ch_status(a:chan, {'part': 'err'}) == 'buffered'
166-
let msg = ch_read(a:chan, {'part': 'err'})
167-
call add(messages, msg)
168-
endwhile
169-
170-
let l:job = ch_getjob(a:chan)
171-
let l:info = job_info(l:job)
158+
let messages = []
159+
function! s:callback(chan, msg) closure
160+
call add(messages, a:msg)
161+
endfunction
172162

163+
function! s:exit_cb(job, exitval) closure
173164
let out = join(messages, "\n")
174165

175166
let status = {
@@ -178,21 +169,22 @@ function! s:async_guru(args) abort
178169
\ 'state': "finished",
179170
\ }
180171

181-
if l:info.exitval
172+
if a:exitval
182173
let status.state = "failed"
183174
endif
184175

185176
call go#statusline#Update(status_dir, status)
186177

187178
if has_key(a:args, 'custom_parse')
188-
call a:args.custom_parse(l:info.exitval, out)
179+
call a:args.custom_parse(a:exitval, out)
189180
else
190-
call s:parse_guru_output(l:info.exitval, out, a:args.mode)
181+
call s:parse_guru_output(a:exitval, out, a:args.mode)
191182
endif
192183
endfunction
193184

194185
let start_options = {
195-
\ 'close_cb': funcref("s:close_cb"),
186+
\ 'callback': funcref("s:callback"),
187+
\ 'exit_cb': funcref("s:exit_cb"),
196188
\ }
197189

198190
if has_key(result, 'stdin_content')

autoload/go/job.vim

+8-19
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,25 @@ function go#job#Spawn(args)
3030
call add(self.messages, a:msg)
3131
endfunction
3232

33-
function cbs.close_cb(chan) dict
34-
let l:job = ch_getjob(a:chan)
35-
let l:status = job_status(l:job)
36-
37-
" the job might be in fail status, we assume by default it's failed.
38-
" However if it's dead, we can use the real exitval
39-
let exitval = 1
40-
if l:status == "dead"
41-
let l:info = job_info(l:job)
42-
let exitval = l:info.exitval
43-
endif
44-
33+
function cbs.exit_cb(job, exitval) dict
4534
if has_key(self, 'custom_cb')
46-
call self.custom_cb(l:job, exitval, self.messages)
35+
call self.custom_cb(a:job, a:exitval, self.messages)
4736
endif
4837

4938
if has_key(self, 'error_info_cb')
50-
call self.error_info_cb(l:job, exitval, self.messages)
39+
call self.error_info_cb(a:job, a:exitval, self.messages)
5140
endif
5241

5342
if get(g:, 'go_echo_command_info', 1)
54-
if exitval == 0
43+
if a:exitval == 0
5544
call go#util#EchoSuccess("SUCCESS")
5645
else
5746
call go#util#EchoError("FAILED")
5847
endif
5948
endif
6049

6150
let l:listtype = go#list#Type("quickfix")
62-
if exitval == 0
51+
if a:exitval == 0
6352
call go#list#Clean(l:listtype)
6453
call go#list#Window(l:listtype)
6554
return
@@ -99,9 +88,9 @@ function go#job#Spawn(args)
9988
let cbs.callback = a:args.callback
10089
endif
10190

102-
" override close callback handler if user provided it
103-
if has_key(a:args, 'close_cb')
104-
let cbs.close_cb = a:args.close_cb
91+
" override exit callback handler if user provided it
92+
if has_key(a:args, 'exit_cb')
93+
let cbs.exit_cb = a:args.exit_cb
10594
endif
10695

10796
return cbs

autoload/go/lint.vim

+3-12
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,14 @@ function s:lint_job(args)
260260
copen
261261
endfunction
262262

263-
function! s:close_cb(chan) closure
264-
let l:job = ch_getjob(a:chan)
265-
let l:status = job_status(l:job)
266-
267-
let exitval = 1
268-
if l:status == "dead"
269-
let l:info = job_info(l:job)
270-
let exitval = l:info.exitval
271-
endif
272-
263+
function! s:exit_cb(job, exitval) closure
273264
let status = {
274265
\ 'desc': 'last status',
275266
\ 'type': "gometaliner",
276267
\ 'state': "finished",
277268
\ }
278269

279-
if exitval
270+
if a:exitval
280271
let status.state = "failed"
281272
endif
282273

@@ -305,7 +296,7 @@ function s:lint_job(args)
305296

306297
let start_options = {
307298
\ 'callback': funcref("s:callback"),
308-
\ 'close_cb': funcref("s:close_cb"),
299+
\ 'exit_cb': funcref("s:exit_cb"),
309300
\ }
310301

311302
call job_start(a:args.cmd, start_options)

autoload/go/rename.vim

+4-7
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,25 @@ function s:rename_job(args)
7171

7272
let status_dir = expand('%:p:h')
7373

74-
function! s:close_cb(chan) closure
75-
let l:job = ch_getjob(a:chan)
76-
let l:info = job_info(l:job)
77-
74+
function! s:exit_cb(job, exitval) closure
7875
let status = {
7976
\ 'desc': 'last status',
8077
\ 'type': "gorename",
8178
\ 'state': "finished",
8279
\ }
8380

84-
if l:info.exitval
81+
if a:exitval
8582
let status.state = "failed"
8683
endif
8784

8885
call go#statusline#Update(status_dir, status)
8986

90-
call s:parse_errors(l:info.exitval, a:args.bang, messages)
87+
call s:parse_errors(a:exitval, a:args.bang, messages)
9188
endfunction
9289

9390
let start_options = {
9491
\ 'callback': funcref("s:callback"),
95-
\ 'close_cb': funcref("s:close_cb"),
92+
\ 'exit_cb': funcref("s:exit_cb"),
9693
\ }
9794

9895
" modify GOPATH if needed

0 commit comments

Comments
 (0)