kmesh-net / kmesh

High Performance ServiceMesh Data Plane Based on Programmable Kernel
https://kmesh.net
Apache License 2.0
363 stars 46 forks source link

Cleanup: eliminating stopCh defined everywhere #497

Closed hzxuzhonghu closed 10 hours ago

hzxuzhonghu commented 3 days ago

This is the searching result.

https://github.com/search?q=repo%3Akmesh-net%2Fkmesh%20make(chan%20struct%7B%7D)&type=code

By passing stop channel to each module's Start/Run method, we can control each module globally. And even more, by doing so, we could further eliminate defer stop stuff

    c := controller.NewController(configs, bpfLoader.GetBpfKmeshWorkload(), configs.BpfConfig.BpfFsPath, configs.BpfConfig.EnableBpfLog)
    if err := c.Start(); err != nil {
        return err
    }
    log.Info("controller Start successful")
    defer c.Stop()
Okabe-Rintarou-0 commented 3 days ago

What about using context.WithCancel, it's a native way to simplify goroutine canceling.

Okabe-Rintarou-0 commented 3 days ago

/assign

hzxuzhonghu commented 3 days ago

No much difference, ctx also good