Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in arm64 docker #10

Closed
drunkod opened this issue Apr 10, 2023 · 5 comments
Closed

Error in arm64 docker #10

drunkod opened this issue Apr 10, 2023 · 5 comments

Comments

@drunkod
Copy link

drunkod commented Apr 10, 2023

`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
Copy link
Author

drunkod commented Apr 10, 2023

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 added a commit that referenced this issue Apr 11, 2023
@ioppermann
Copy link
Member

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
Copy link
Author

drunkod commented Apr 11, 2023

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
Copy link
Author

drunkod commented Apr 14, 2023

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
Copy link
Member

Hey @drunkod
Thanks for your support 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants