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

panic: runtime error: index out of range #7

Open
marutinandanpandya opened this issue Dec 24, 2018 · 1 comment
Open

panic: runtime error: index out of range #7

marutinandanpandya opened this issue Dec 24, 2018 · 1 comment

Comments

@marutinandanpandya
Copy link

I have installed passenger_exporter on ubuntu 16.04 system and the process kills itself after some random time.

$ sudo systemctl status passenger_exporter
● passenger_exporter.service - Passenger Exporter
   Loaded: loaded (/etc/systemd/system/passenger_exporter.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-12-24 09:39:45 UTC; 1h 39min ago
  Process: 1453 ExecStart=/usr/local/bin/passenger_exporter -passenger.command /usr/sbin/passenger-status --show=xml (code=exited, status=2)
 Main PID: 1453 (code=exited, status=2)

Dec 24 09:28:34 localhost systemd[1]: Started Passenger Exporter.
Dec 24 09:28:34 localhost passenger_exporter[1453]: time="2018-12-24T09:28:34Z" level=info msg="Starting passenger-exporter (version=, bra
Dec 24 09:28:34 localhost passenger_exporter[1453]: time="2018-12-24T09:28:34Z" level=info msg="Build context (go=go1.11, user=, date=)" s
Dec 24 09:28:34 localhost passenger_exporter[1453]: time="2018-12-24T09:28:34Z" level=info msg="Listening on :9149" source="passenger_expo
Dec 24 09:39:45 localhost passenger_exporter[1453]: panic: runtime error: index out of range
Dec 24 09:39:45 localhost systemd[1]: passenger_exporter.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Dec 24 09:39:45 localhost systemd[1]: passenger_exporter.service: Unit entered failed state.
Dec 24 09:39:45 localhost systemd[1]: passenger_exporter.service: Failed with result 'exit-code'.
@jgrancell
Copy link

The issue behind this error is in this line:

found[id] = p.PID

The length of found is set based on the length of the old variable. In some edge cases the id value can be equal to the length of found, but since found is 0-based as an array that causes the index out of range panic.

I've merged this fix into my branch, which identifies when the panic conditions are present and uses append() to append the values to the end of found instead of inserting into an invalid index.

if id >= len(old) {
  log.Errorf("ID is out of bounds. Old len: %v, ID: %v", len(old), id)
  found = append(found, p.PID)
} else {
  found[id] = p.PID
}

I'll get a PR generated in the next few days against this repo.

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

2 participants