mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 14:32:33 +00:00
runtime: close span before return from function in case of error
Return before closing span will cause invalid spans, so span should be closed before function return. Fixes: #3424 Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
parent
7d1a956471
commit
85f5ae190e
@ -606,11 +606,16 @@ func (c *Container) unmountHostMounts(ctx context.Context) error {
|
|||||||
span, ctx := katatrace.Trace(ctx, c.Logger(), "unmountHostMounts", containerTracingTags, map[string]string{"container_id": c.id})
|
span, ctx := katatrace.Trace(ctx, c.Logger(), "unmountHostMounts", containerTracingTags, map[string]string{"container_id": c.id})
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
for _, m := range c.mounts {
|
unmountFunc := func(m Mount) (err error) {
|
||||||
if m.HostPath != "" {
|
|
||||||
span, _ := katatrace.Trace(ctx, c.Logger(), "unmount", containerTracingTags, map[string]string{"container_id": c.id, "host-path": m.HostPath})
|
span, _ := katatrace.Trace(ctx, c.Logger(), "unmount", containerTracingTags, map[string]string{"container_id": c.id, "host-path": m.HostPath})
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
katatrace.AddTags(span, "error", err)
|
||||||
|
}
|
||||||
|
span.End()
|
||||||
|
}()
|
||||||
|
|
||||||
if err := syscall.Unmount(m.HostPath, syscall.MNT_DETACH|UmountNoFollow); err != nil {
|
if err = syscall.Unmount(m.HostPath, syscall.MNT_DETACH|UmountNoFollow); err != nil {
|
||||||
c.Logger().WithFields(logrus.Fields{
|
c.Logger().WithFields(logrus.Fields{
|
||||||
"host-path": m.HostPath,
|
"host-path": m.HostPath,
|
||||||
"error": err,
|
"error": err,
|
||||||
@ -631,8 +636,14 @@ func (c *Container) unmountHostMounts(ctx context.Context) error {
|
|||||||
syscall.Rmdir(m.HostPath)
|
syscall.Rmdir(m.HostPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
span.End()
|
for _, m := range c.mounts {
|
||||||
|
if m.HostPath != "" {
|
||||||
|
if err := unmountFunc(m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user