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

FreeBSD: couldn't get uname: cannot allocate memory #2809

Open
pando85 opened this issue Sep 22, 2023 · 8 comments
Open

FreeBSD: couldn't get uname: cannot allocate memory #2809

pando85 opened this issue Sep 22, 2023 · 8 comments

Comments

@pando85
Copy link

pando85 commented Sep 22, 2023

Host operating system: output of uname -a

FreeBSD XXXX 14.0-CURRENT FreeBSD 14.0-CURRENT #1 RELENG_2_7_0-n255866-686c8d3c1f0: Wed Jun 28 04:21:19 UTC 2023     root@freebsd:/var/jenkins/workspace/pfSense-CE-snapshots-2_7_0-main/obj/amd64/LwYAddCr/var/jenkins/workspace/pfSense-CE-snapshots-2_7_0-main/sources/FreeBSD-src-RELENG_2_7_0/amd64.amd64/sys/pfSense amd64

node_exporter version: output of node_exporter --version

node_exporter, version 1.5.0 (branch: release-1.5, revision: 5)
  build user:       nobody
  build date:       
  go version:       go1.20.3
  platform:         freebsd/amd64

node_exporter command line flags

/usr/local/bin/node_exporter --web.listen-address=192.168.192.1:9100 --collector.textfile.directory=/var/tmp/node_exporter --collector.boottime --collector.cpu --collector.exec --collector.filesystem --collector.loadavg --collector.meminfo --collector.netdev --collector.textfile --collector.time --log.level=warn

node_exporter log output

s=2023-09-22T20:05:32.809Z caller=collector.go:169 level=error msg="collector failed" name=uname duration_seconds=0.000157114 err="cannot allocate memory" 

Are you running node_exporter in Docker?

No

What did you do that produced an error?

Run node_exporter.

What did you expect to see?

node_uname_info metric.

What did you see instead?

node_scrape_collector_success{collector="uname"} 0
@MarshmallowSoup
Copy link

Same here

@discordianfish
Copy link
Member

I suppose this comes from here:

if err := unix.Uname(&utsname); err != nil {

Can create a minimal program using unix.Uname() to reproduce this? Might be a golang issue. Also, have you tried the current master version?

@joelsdc
Copy link

joelsdc commented Jan 10, 2024

Happening also on latest pfSense OSS v2.7.2 (based on FreeBSD 14)

@discordianfish
Copy link
Member

Please anyone try to reproduce this by running the following:

package main

import (
	"log"
	"golang.org/x/sys/unix"
)

func main() {
	var utsname unix.Utsname
	if err := unix.Uname(&utsname); err != nil {
		log.Fatal(err)
	}
	log.Printf("%s", utsname)
}

@seeplusplus
Copy link
Contributor

Please anyone try to reproduce this by running the following:

package main

import (
	"log"
	"golang.org/x/sys/unix"
)

func main() {
	var utsname unix.Utsname
	if err := unix.Uname(&utsname); err != nil {
		log.Fatal(err)
	}
	log.Printf("%s", utsname)
}

Yes, this reproduces the exact same input described above:

2024/02/07 17:11:22 cannot allocate memory

@seeplusplus
Copy link
Contributor

seeplusplus commented Feb 7, 2024

I have tested, by building the above with the entirety of
https://cs.opensource.google/go/x/sys/+/master:unix/syscall_freebsd.go;l=169-213;bpv=0?q=Uname&ss=go%2Fx%2Fsys
commented out and progressively uncommenting line by line and running each executable as I go along and have determined that this line chunk:

         mib = []_C_int{CTL_KERN, KERN_VERSION}
          n = unsafe.Sizeof(uname.Version)
          if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
                 return err
}   

to be the cause. Your minimal repro code snippet works if I leave everything but this section commented out, and continues to fail to alloc if I leave this chunk in. I have never written Go, so I'm not sure if I'll be able to fix this but wanted to drop this here in case anyone else lands here.

Edit

https://man.freebsd.org/cgi/man.cgi?sysctl(3)

https://cs.opensource.google/go/x/sys/+/master:unix/ztypes_freebsd_amd64.go;l=639-645;bpv=0?q=Utsname&ss=go%2Fx%2Fsys

This is because the Version field of Utsname is too small. It's 256 bytes above, but in pfsense this string is larger.

@discordianfish
Copy link
Member

@seeplusplus Great job debugging and thanks for opening the golang issue!

@seeplusplus
Copy link
Contributor

@seeplusplus Great job debugging and thanks for opening the golang issue!

The fix for the issue in sys/unix was merged to master this morning. It seems like there are some other issues in this repo preventing successful builds on FreeBSD though. I started taking a look a those over the weekend.

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

Successfully merging a pull request may close this issue.

5 participants