datarhei / core

datarhei Core is management for FFmpeg processes without development effort. Whether your streaming has one viewer or a million, we have the tools to help you develop, deploy and manage any video project at any stage. We've solved the challenging problems so you can focus on your application, not your infrastructure.
https://docs.datarhei.com/core
Apache License 2.0
197 stars 45 forks source link

Error in arm64 docker #10

Closed drunkod closed 1 year ago

drunkod commented 1 year ago

`panic: runtime error: index out of range [0] with length 0

goroutine 20 [running]: github.com/datarhei/core/v16/psutil.(util).cpuTimes(0x40000a8edc?) /dist/core/psutil/psutil.go:288 +0x184 github.com/datarhei/core/v16/psutil.(util).collect(0x40000a8f70?) /dist/core/psutil/psutil.go:247 +0x28 github.com/datarhei/core/v16/psutil.(util).tick(0x400013c000, {0xd799c0, 0x40000a4910}, 0x0?) /dist/core/psutil/psutil.go:236 +0xe8 created by github.com/datarhei/core/v16/psutil.(util).Start.func1 /dist/core/psutil/psutil.go:133 +0xd8`

drunkod commented 1 year ago

Chatgpt search:

The error message indicates that there was an attempt to access an element of an empty slice. This can happen when the slice has no elements and an attempt is made to access an element at a specific index.

In the provided code snippet, the error occurs in the cpuTimes() method of the util struct. Specifically, it occurs when the cpu.Times() function returns an error and the times slice is empty. This can happen if there is an issue with obtaining the CPU times statistics.

To fix the issue, you can add a check to ensure that the times slice has at least one element before attempting to access it. For example:

times, err := cpu.Times(false)
if err != nil {
    return nil, err
}

if len(times) == 0 {
    return nil, errors.New("cpu.Times() returned an empty slice")
}

s := &cpuTimesStat{
    total:  cpuTotal(&times[0]),
    system: times[0].System,
    user:   times[0].User,
    idle:   times[0].Idle,
}

s.other = s.total - s.system - s.user - s.idle

return s, nil
ioppermann commented 1 year ago

Thanks for the report.

Would you share what your host system is and which docker run ... command you are using that led to this error? I wasn't able to reproduce it.

drunkod commented 1 year ago

Thanks for the report.

Would you share what your host system is and which docker run ... command you are using that led to this error? I wasn't able to reproduce it.

Thanks, in Android Linux under PRoot, Termux... Maybe because of the lack of access to CPU times statistics. For example, if the system does not have any CPUs...

drunkod commented 1 year ago

Thanks for the report.

Would you share what your host system is and which docker run ... command you are using that led to this error? I wasn't able to reproduce it.

Thank you so much your code helped solve my problem !!!

jstabenow commented 1 year ago

Hey @drunkod Thanks for your support 👍