@@ -70,53 +70,46 @@ function Runner:_log_raw_output(output)
70
70
end
71
71
72
72
function Runner :_run_git_job ()
73
- local handle
73
+ local handle , pid
74
74
local stdout = vim .loop .new_pipe (false )
75
75
local stderr = vim .loop .new_pipe (false )
76
76
local timer = vim .loop .new_timer ()
77
77
78
- local function on_finish (rc , signal )
79
- log .line (" git" , " rc=%d, signal=%s" , tostring (rc ), tostring (signal ))
78
+ local function on_finish (rc )
80
79
self .rc = rc or 0
81
-
82
- if timer and not timer :is_closing () then
83
- timer :stop ()
84
- timer :close ()
85
- end
86
- if stdout and not stdout :is_closing () then
87
- stdout :read_stop ()
88
- stdout :close ()
89
- end
90
- if stderr and not stderr :is_closing () then
91
- stderr :read_stop ()
92
- stderr :close ()
80
+ if timer :is_closing () or stdout :is_closing () or stderr :is_closing () or (handle and handle :is_closing ()) then
81
+ return
93
82
end
94
- if handle and not handle :is_closing () then
83
+ timer :stop ()
84
+ timer :close ()
85
+ stdout :read_stop ()
86
+ stderr :read_stop ()
87
+ stdout :close ()
88
+ stderr :close ()
89
+ if handle then
95
90
handle :close ()
96
91
end
92
+
93
+ pcall (vim .loop .kill , pid )
97
94
end
98
95
99
96
local opts = self :_getopts (stdout , stderr )
100
97
log .line (" git" , " running job with timeout %dms" , self .timeout )
101
98
log .line (" git" , " git %s" , table.concat (utils .array_remove_nils (opts .args ), " " ))
102
99
103
- handle = vim .loop .spawn (
100
+ handle , pid = vim .loop .spawn (
104
101
" git" ,
105
102
opts ,
106
- vim .schedule_wrap (function (rc , signal )
107
- on_finish (rc , signal )
103
+ vim .schedule_wrap (function (rc )
104
+ on_finish (rc )
108
105
end )
109
106
)
110
107
111
108
timer :start (
112
109
self .timeout ,
113
110
0 ,
114
111
vim .schedule_wrap (function ()
115
- log .line (" git" , " timed out, killing" )
116
- self .timed_out = true
117
- if handle then
118
- handle :kill " sigkill"
119
- end
112
+ on_finish (- 1 )
120
113
end )
121
114
)
122
115
142
135
143
136
function Runner :_wait ()
144
137
local function is_done ()
145
- return self .rc ~= nil or self . timed_out
138
+ return self .rc ~= nil
146
139
end
147
140
148
141
while not vim .wait (30 , is_done ) do
@@ -160,16 +153,15 @@ function Runner.run(opts)
160
153
list_ignored = opts .list_ignored ,
161
154
timeout = opts .timeout or 400 ,
162
155
output = {},
163
- rc = nil ,
164
- timed_out = false ,
156
+ rc = nil , -- -1 indicates timeout
165
157
}, Runner )
166
158
167
159
self :_run_git_job ()
168
160
self :_wait ()
169
161
170
162
log .profile_end (profile )
171
163
172
- if self .timed_out then
164
+ if self .rc == - 1 then
173
165
log .line (" git" , " job timed out %s %s" , opts .project_root , opts .path )
174
166
timeouts = timeouts + 1
175
167
if timeouts == MAX_TIMEOUTS then
0 commit comments