@@ -44,16 +44,14 @@ func (p *LocalPluginRuntime) ensureTraceCtx() context.Context {
4444}
4545
4646func (p * LocalPluginRuntime ) startSpan (name string , attrs ... attribute.KeyValue ) (context.Context , trace.Span ) {
47- ctx := p .ensureTraceCtx ()
48- ctx , sp := p .otelTracer ().Start (ctx , name )
47+ rootCtx := p .ensureTraceCtx ()
48+ ctx , sp := p .otelTracer ().Start (rootCtx , name )
4949 if id , ok := log .IdentityFromContext (ctx ); ok && id .TenantID != "" {
5050 sp .SetAttributes (attribute .String ("tenant_id" , id .TenantID ))
5151 }
5252 if len (attrs ) > 0 {
5353 sp .SetAttributes (attrs ... )
5454 }
55- // keep last context for potential child spans
56- p .traceCtx = ctx
5755 return ctx , sp
5856}
5957
@@ -205,11 +203,15 @@ func (p *LocalPluginRuntime) installDependencies(
205203
206204 defer func () {
207205 if cmd .Process != nil {
208- cmd .Process .Kill ()
206+ err := cmd .Process .Kill ()
207+ if err != nil {
208+ log .Warn ("failed to kill python process" , "error" , err )
209+ }
209210 }
210211 }()
211212
212213 var errMsg strings.Builder
214+ var errMsgMu sync.Mutex
213215 var wg sync.WaitGroup
214216 wg .Add (2 )
215217
@@ -220,14 +222,12 @@ func (p *LocalPluginRuntime) installDependencies(
220222 routinepkg .RoutineLabelKeyMethod : "InitPythonEnvironment" ,
221223 }, func () {
222224 defer wg .Done ()
223- // read stdout
224225 buf := make ([]byte , 1024 )
225226 for {
226227 n , err := stdout .Read (buf )
227228 if err != nil {
228229 break
229230 }
230- // FIXME: move the log to separated layer
231231 log .Info ("installing plugin" , "plugin" , p .Config .Identity (), "output" , string (buf [:n ]))
232232 lastActiveAt = time .Now ()
233233 }
@@ -238,20 +238,23 @@ func (p *LocalPluginRuntime) installDependencies(
238238 routinepkg .RoutineLabelKeyMethod : "InitPythonEnvironment" ,
239239 }, func () {
240240 defer wg .Done ()
241- // read stderr
242241 buf := make ([]byte , 1024 )
243242 for {
244243 n , err := stderr .Read (buf )
245- if err != nil && err != os .ErrClosed {
244+ if err != nil && ! errors . Is ( err , os .ErrClosed ) {
246245 lastActiveAt = time .Now ()
246+ errMsgMu .Lock ()
247247 errMsg .WriteString (string (buf [:n ]))
248+ errMsgMu .Unlock ()
248249 break
249- } else if err == os .ErrClosed {
250+ } else if errors . Is ( err , os .ErrClosed ) {
250251 break
251252 }
252253
253254 if n > 0 {
255+ errMsgMu .Lock ()
254256 errMsg .WriteString (string (buf [:n ]))
257+ errMsgMu .Unlock ()
255258 lastActiveAt = time .Now ()
256259 }
257260 }
@@ -271,11 +274,16 @@ func (p *LocalPluginRuntime) installDependencies(
271274 if time .Since (lastActiveAt ) > time .Duration (
272275 p .appConfig .PythonEnvInitTimeout ,
273276 )* time .Second {
274- cmd .Process .Kill ()
277+ err := cmd .Process .Kill ()
278+ errMsgMu .Lock ()
279+ if err != nil {
280+ errMsg .WriteString (fmt .Sprintf ("failed to kill python process: %s" , err ))
281+ }
275282 errMsg .WriteString (fmt .Sprintf (
276283 "init process exited due to no activity for %d seconds" ,
277284 p .appConfig .PythonEnvInitTimeout ,
278285 ))
286+ errMsgMu .Unlock ()
279287 break
280288 }
281289 }
0 commit comments