safeconn

package module
v0.0.0-...-951e9ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: GPL-3.0 Imports: 1 Imported by: 1

README

Safe Conn

GoDoc Build Status codecov

The safeconn Go package provides nil-safe accessors for net.Conn properties.

These functions exist because gvisor-based network stacks can cause the connection's addresses to disappear very quickly after a connection is closed, leading to segfaults when accessing LocalAddr or RemoteAddr. By centralizing nil checks here, we defend against this platform-specific behavior.

Usage

import "github.com/bassosimone/safeconn"

// Get local address safely (returns "" if conn or addr is nil)
localAddr := safeconn.LocalAddr(conn)

// Get remote address safely
remoteAddr := safeconn.RemoteAddr(conn)

// Get network type safely
network := safeconn.Network(conn)

Installation

go get github.com/bassosimone/safeconn

Development

go test -v .
go test -v -cover .

License

SPDX-License-Identifier: GPL-3.0-or-later

History

Adapted from:

Documentation

Overview

Package safeconn provides nil-safe accessors for net.Conn properties.

These functions exist because gvisor-based network stacks can cause the connection's addresses to disappear very quickly after a connection is closed, leading to segfaults when accessing LocalAddr or RemoteAddr. By centralizing nil checks here, we defend against this platform-specific behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocalAddr

func LocalAddr(conn net.Conn) (value string)

LocalAddr returns the conn local address or the empty string.

func Network

func Network(conn net.Conn) (value string)

Network returns the conn network or the empty string.

func RemoteAddr

func RemoteAddr(conn net.Conn) (value string)

RemoteAddr returns the conn remote address or the empty string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL