probelabs/goreplay · error

socket mmap error: %v

Error message

socket mmap error: %v

What it means

NewSocket failed to mmap the ring buffer of BLOCKSIZE*BLOCKNR bytes into the process (out of memory, hugepage unavailability, or limits on mapped memory); the fd is closed and the wrapped errno returned, so the socket is unusable.

Source

Thrown at internal/capture/sock_linux.go:123

		Block_nr:   BLOCKNR,
		Frame_size: FRAMESIZE,
		Frame_nr:   FRAMENR,
	}
	err = unix.SetsockoptTpacketReq(sock.fd, unix.SOL_PACKET, unix.PACKET_RX_RING, tp)
	if err != nil {
		unix.Close(fd)
		return nil, fmt.Errorf("setsockopt packet_rx_ring: %v", err)
	}
	sock.buf, err = unix.Mmap(
		sock.fd,
		0,
		BLOCKSIZE*BLOCKNR,
		unix.PROT_READ|unix.PROT_WRITE,
		unix.MAP_SHARED|MAPHUGE2MB,
	)
	if err != nil {
		unix.Close(fd)
		return nil, fmt.Errorf("socket mmap error: %v", err)
	}
	return sock, nil
}

// ReadPacketData implements gopacket.PacketDataSource.
func (sock *SockRaw) ReadPacketData() (buf []byte, ci gopacket.CaptureInfo, err error) {
	sock.mu.Lock()
	defer sock.mu.Unlock()
	var tpHdr *unix.Tpacket2Hdr
	poll := &unix.PollFd{
		Fd:     int32(sock.fd),
		Events: unix.POLLIN,
	}
	var i int
read:
	i = int(sock.frame * FRAMESIZE)
	tpHdr = (*unix.Tpacket2Hdr)(unsafe.Pointer(&sock.buf[i]))
	sock.frame = (sock.frame + 1) % FRAMENR

View on GitHub (pinned to 251e45abd2)

Solutions

  1. Check available memory and vm.max_map_count / ulimit -l
  2. Ensure 2MB hugepages are reserved (nr_hugepages) since MAPHUGE2MB is requested
  3. Reduce ring buffer constants if the host cannot back the allocation
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/capture/sock_linux.go:123 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of probelabs/goreplay@251e45abd2 (2026-09-02). Data as JSON: /api/errors/352a08e6846cca38. Report an issue: GitHub.