Skip to content

os/exec:Command line execution exception when stopping service #61739

@kwb0523

Description

@kwb0523

What version of Go are you using (go version)?

$ go version
go1.19.4

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

x86 linux

go env Output
$ go env

What did you do?

In the ‘kmesh service’ of the application program, I called another proogram ‘mdacore enable’ through exec.Command interface, it is mainly used to attach the ebpf program, and there are no problems with service startup and running. However, when stopping the service program, I need to call 'mdacore disable' to detach the ebpf program. Sometimes it can be detached normally, but sometimes it fails.

The main code snippet is as follows:

//actions at service startup
func StartMda() error {
        cmd := exec.Command("mdacore", "enable")
        output, err := cmd.CombinedOutput()
        fmt.Println(string(output))
        return err
}

//action when service is stopped
func setupCloseHandler() {
        ch := make(chan os.Signal, 1)
        signal.Notify(ch, syscall.SIGKILL, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT, syscall.SIGTSTP)

        <-ch

        command.StopServer()
        controller.Stop()
        bpf.Stop()

        log.Warn("signal Notify exit")
}

func Stop() {
        var err error

 if config.EnableMda {
                var wg sync.WaitGroup
                wg.Add(1)
                go StopMda(&wg)
                wg.Wait()
                return
        }

        return
}

func StopMda(waitGroup *sync.WaitGroup) {
        defer waitGroup.Done()
        cmd := exec.Command("mdacore", "disable")
        output, err := cmd.CombinedOutput()
        if err != nil {
                log.Errorf("failed detach when stop mda, err:%s", err)
                return
        }

        fmt.Println(string(output))
        return
}

// Successful situations
○ kmesh.service - kmesh is a eBPF-based service mesh kernel solution
Loaded: loaded (/usr/lib/systemd/system/kmesh.service; disabled; vendor preset: disabled)
Active: inactive (dead)

Aug 03 22:09:57 kmesh-daemon[157978]: enable serviceMesh accelerating success!
Aug 03 22:09:57 kmesh-daemon[157978]: time="2023-08-03T22:09:57+08:00" level=info msg="bpf Start successful" subsys=manager
Aug 03 22:09:57 kmesh-daemon[157978]: time="2023-08-03T22:09:57+08:00" level=info msg="controller Start successful" subsys=manager
Aug 03 22:09:57 kmesh-daemon[157978]: time="2023-08-03T22:09:57+08:00" level=info msg="command StartServer successful" subsys=manager
Aug 03 22:09:58 systemd[1]: Stopping kmesh is a eBPF-based service mesh kernel solution...
Aug 03 22:09:58 kmesh-daemon[157978]: disable serviceMesh accelerating success!
Aug 03 22:09:58 kmesh-daemon[157978]: time="2023-08-03T22:09:58+08:00" level=warning msg="signal Notify exit" subsys=manager
Aug 03 22:09:58 systemd[1]: kmesh.service: Deactivated successfully.
Aug 03 22:09:58 systemd[1]: Stopped kmesh is a eBPF-based service mesh kernel solution.
Aug 03 22:09:58 systemd[1]: kmesh.service: Consumed 1.131s CPU time.

// failed situations
○ kmesh.service - kmesh is a eBPF-based service mesh kernel solution
Loaded: loaded (/usr/lib/systemd/system/kmesh.service; disabled; vendor preset: disabled)
Active: inactive (dead)

Aug 03 22:10:04 kmesh-daemon[158015]: enable serviceMesh accelerating success!
Aug 03 22:10:04 kmesh-daemon[158015]: time="2023-08-03T22:10:04+08:00" level=info msg="bpf Start successful" subsys=manager
Aug 03 22:10:04 kmesh-daemon[158015]: time="2023-08-03T22:10:04+08:00" level=info msg="controller Start successful" subsys=manager
Aug 03 22:10:04 kmesh-daemon[158015]: time="2023-08-03T22:10:04+08:00" level=info msg="command StartServer successful" subsys=manager
Aug 03 22:10:06 systemd[1]: Stopping kmesh is a eBPF-based service mesh kernel solution...
Aug 03 22:10:06 kmesh-daemon[158015]: time="2023-08-03T22:10:06+08:00" level=error msg="failed detach when stop mda, err:signal: terminated" subsys=pkg/bpf
Aug 03 22:10:06 kmesh-daemon[158015]: time="2023-08-03T22:10:06+08:00" level=warning msg="signal Notify exit" subsys=manager
Aug 03 22:10:06 systemd[1]: kmesh.service: Deactivated successfully.
Aug 03 22:10:06 systemd[1]: Stopped kmesh is a eBPF-based service mesh kernel solution.
Aug 03 22:10:06 systemd[1]: kmesh.service: Consumed 1.126s CPU time.

What did you expect to see?

Did I use it improperly when I stopped? or any bugs here ?Can someone give me some advice? Thank you very much!

What did you see instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions