RepoPilotOpen in app β†’

panjf2000/gnet

πŸš€ gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.

Healthy

Healthy across all four use cases

weakest axis
Use as dependencyHealthy

Permissive license, no critical CVEs, actively maintained β€” safe to depend on.

Fork & modifyHealthy

Has a license, tests, and CI β€” clean foundation to fork and modify.

Learn fromHealthy

Documented and popular β€” useful reference codebase to read through.

Deploy as-isHealthy

No critical CVEs, sane security posture β€” runnable as-is.

  • βœ“Last commit 5w ago
  • βœ“6 active contributors
  • βœ“Apache-2.0 licensed
Show all 6 evidence items β†’
  • βœ“CI configured
  • βœ“Tests present
  • ⚠Single-maintainer risk β€” top contributor 94% of recent commits

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Healthy" badge

Paste into your README β€” live-updates from the latest cached analysis.

Variant:
RepoPilot: Healthy
[![RepoPilot: Healthy](https://repopilot.app/api/badge/panjf2000/gnet)](https://repopilot.app/r/panjf2000/gnet)

Paste at the top of your README.md β€” renders inline like a shields.io badge.

β–ΈPreview social card (1200Γ—630)

This card auto-renders when someone shares https://repopilot.app/r/panjf2000/gnet on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: panjf2000/gnet

Generated by RepoPilot Β· 2026-05-09 Β· Source

πŸ€–Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale β€” STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI Β· unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/panjf2000/gnet shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything β€” but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

GO β€” Healthy across all four use cases

  • Last commit 5w ago
  • 6 active contributors
  • Apache-2.0 licensed
  • CI configured
  • Tests present
  • ⚠ Single-maintainer risk β€” top contributor 94% of recent commits

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

βœ…Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live panjf2000/gnet repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale β€” regenerate it at repopilot.app/r/panjf2000/gnet.

What it runs against: a local clone of panjf2000/gnet β€” the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in panjf2000/gnet | Confirms the artifact applies here, not a fork | | 2 | License is still Apache-2.0 | Catches relicense before you depend on it | | 3 | Default branch dev exists | Catches branch renames | | 4 | Last commit ≀ 67 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> β€” paste this script from inside your clone of <code>panjf2000/gnet</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of panjf2000/gnet. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/panjf2000/gnet.git
#   cd gnet
#
# Then paste this script. Every check is read-only β€” no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of panjf2000/gnet and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "panjf2000/gnet(\\.git)?\\b" \\
  && ok "origin remote is panjf2000/gnet" \\
  || miss "origin remote is not panjf2000/gnet (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(Apache-2\\.0)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"Apache-2\\.0\"" package.json 2>/dev/null) \\
  && ok "license is Apache-2.0" \\
  || miss "license drift β€” was Apache-2.0 at generation time"

# 3. Default branch
git rev-parse --verify dev >/dev/null 2>&1 \\
  && ok "default branch dev exists" \\
  || miss "default branch dev no longer exists"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 67 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~37d)"
else
  miss "last commit was $days_since_last days ago β€” artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) β€” safe to trust"
else
  echo "artifact has $fail stale claim(s) β€” regenerate at https://repopilot.app/r/panjf2000/gnet"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

⚑TL;DR

gnet is a high-performance, event-driven networking framework written in pure Go that uses epoll (Linux) and kqueue (BSD/macOS) to handle thousands of concurrent connections with minimal memory overhead. It achieves significantly better throughput and lower latency than Go's standard net package by leveraging non-blocking I/O and avoiding goroutine-per-connection overhead. Flat architecture with platform-specific build tags: core event loop logic in eventloop_unix.go/eventloop_windows.go, connection lifecycle in connection_.go files, acceptor patterns in acceptor_.go, and utilities in conn_map.go (connection tracking), load_balancer.go (round-robin balancing), and internal/gfd (file descriptor wrapper). Tests live alongside implementation files.

πŸ‘₯Who it's for

Go developers building high-concurrency network services (game servers, message brokers, real-time systems, load balancers) who need sub-millisecond latencies and can handle the callback-based event loop programming model instead of the familiar goroutine-per-connection pattern.

🌱Maturity & risk

Production-ready and actively maintained. The project has comprehensive CI/CD across multiple platforms (Linux, macOS, BSD, Windows via separate codepaths), extensive test coverage (gnet_test.go, eventloop_unix_test.go, conn_matrix_test.go), and uses semantic versioning (v2 module). Last activity is recent and visible through GitHub Actions workflows.

Low-to-moderate risk: single maintainer (panjf2000) is a concentration point, but the codebase is stable with infrequent breaking changes (v2 is mature). OS-specific code paths (acceptor_unix.go, connection_linux.go, engine_windows.go) add maintenance burden. Dependencies are minimal (ants worker pool, zap logging, valyala bytebuffer) and well-established.

Active areas of work

Active maintenance with focused effort on performance optimization (workflows test_gc_opt.yml, test_poll_opt.yml indicate GC and polling tuning), cross-platform stability (cross-compile-bsd.yml), and security scanning (codeql.yml). No major breaking changes planned for v2β€”work is incremental hardening.

πŸš€Get running

Clone the repository and run tests to verify setup:

git clone https://github.com/panjf2000/gnet.git
cd gnet
go mod download
go test -v ./...

No external services required; minimal dependencies auto-fetched via go mod.

Daily commands: No dev server in traditional senseβ€”gnet is a library. Test the example server pattern by examining gnet_test.go, then write your own using the Serve() API with custom handlers. Run unit tests: go test -race -v ./... to catch data races.

πŸ—ΊοΈMap of the codebase

  • gnet.go: Public API surfaceβ€”defines Engine interface, Serve function, and Conn interface that users interact with
  • eventloop_unix.go: Core event loop for Linux/Unix using epoll; handles connection accept, read, write, and callback dispatch
  • eventloop_windows.go: Windows-specific event loop using IOCP instead of epoll; parallel to Unix loop
  • connection_linux.go: Linux-specific connection state and syscall optimization (TCP_NODELAY, SO_REUSEADDR)
  • options.go: Configuration options and callback handler interface definitions (OnOpen, OnData, OnClose, OnTick)
  • conn_matrix.go: Lock-free connection tracking matrix for rapid lookups; critical for scaling to thousands of connections
  • load_balancer.go: Distributes connections across multiple eventloops; implements round-robin or least-loaded policies
  • internal/gfd/gfd.go: File descriptor wrapper for tracking and cleanup; prevents FD exhaustion

πŸ› οΈHow to make changes

Adding protocol support: Extend eventloop_unix.go and eventloop_windows.go OnData handlers. Adding platform: Create connection_os.go, acceptor_os.go, engine_os.go using syscall constants from golang.org/x/sys/os. Optimizing memory: Edit conn_map.go or conn_matrix.go for connection tracking. Adding handlers: See options.go for the full callback interface (OnOpen, OnData, OnClose, OnTick, OnShutdown). Most changes require platform-specific code, so check build tags carefully.

πŸͺ€Traps & gotchas

OS-specific behavior: Code builds differently on Linux (epoll), macOS/BSD (kqueue), and Windows (IOCP)β€”test your changes on target platform. Callback blocking: OnData/OnClose handlers are synchronous in the event loop; long operations block all connections in that loop. Memory pooling: bytebufferpool reuses buffersβ€”never hold references after returning from OnData. Build tags: Files like connection_linux.go only compile on Linux; read build constraints. Goroutine limits: Default is NumCPU event loops; tuning via NumLoops option is required for high concurrency on weak hardware.

πŸ’‘Concepts to learn

  • epoll / kqueue β€” These are the OS syscalls gnet wrapsβ€”understanding how they multiplex I/O is critical to diagnosing performance issues and avoiding common blocking mistakes
  • Reactor Pattern (event-driven) β€” gnet is a Reactorβ€”a single thread dispatches callbacks instead of spawning goroutines per connection; you must avoid blocking in callbacks
  • Lock-free ring buffers / matrix indexing β€” conn_matrix.go uses clever lock-free data structures for connection tracking; understanding this is key to safe concurrent access without mutexes
  • TCP_NODELAY and SO_REUSEADDR socket options β€” gnet sets these automatically in connection_linux.go / connection_unix.go; knowing why (Nagle disable, port reuse on restart) helps optimize latency-sensitive apps
  • Object pooling / buffer reuse β€” gnet reuses buffers via valyala/bytebufferpool to reduce GC pressure; critical for sustained high throughput
  • IOCP (I/O Completion Ports) β€” Windows-specific alternative to epoll/kqueue; engine_windows.go and eventloop_windows.go implement thisβ€”understand it to port features across platforms
  • Goroutine-per-connection vs. event loop tradeoff β€” gnet abandons Go's typical goroutine model for lower memory and fewer context switches; requires callback-based code which is a paradigm shift from net package
  • valyala/fasthttp β€” HTTP-specific event-driven server also optimized for high throughput; complementary if you want HTTP on top of gnet
  • eycorsican/go-tun2socks β€” Another high-performance Go networking project using syscalls directly; similar performance-first philosophy
  • panjf2000/ants β€” Worker goroutine pool by same author, often paired with gnet to safely dispatch OnData callbacks to background jobs
  • xtaci/kcptun β€” UDP-based protocol transport in pure Go; complementary transport layer alternative to gnet's TCP focus
  • google/gvisor β€” Userspace network stack in Go; alternative architecture for network isolation (heavier than gnet, different use case)

πŸͺ„PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive unit tests for connection_linux.go and connection_bsd.go

The repo has platform-specific connection implementations (connection_linux.go, connection_bsd.go, connection_unix.go, connection_windows.go) but only basic test files exist (os_unix_test.go, os_windows_test.go). Linux and BSD connection handling deserves dedicated test coverage for edge cases like TCP_NODELAY, SO_REUSEADDR, and platform-specific socket options that differ between systems.

  • [ ] Create connection_linux_test.go with tests for Linux-specific socket options and epoll integration
  • [ ] Create connection_bsd_test.go with tests for BSD-specific socket options and kqueue integration
  • [ ] Test edge cases like connection shutdown, option setting failures, and platform capability detection
  • [ ] Reference existing connection_unix.go implementation to identify untested code paths

Add load balancer strategy tests and documentation in load_balancer.go

The load_balancer.go file exists but there are no corresponding unit tests (no load_balancer_test.go file visible). Given gnet's focus on high-performance event-driven networking, the load balancing strategy for distributing connections across event loops is critical. This needs thorough testing for fairness, correctness, and performance under various scenarios.

  • [ ] Create load_balancer_test.go with tests for different balancing strategies (round-robin, least-loaded, etc.)
  • [ ] Test load distribution correctness under uneven connection patterns and connection churn
  • [ ] Add benchmarks comparing different load balancer implementations
  • [ ] Document the load balancing algorithm choice and trade-offs in a dedicated section of README.md

Implement cross-platform buffer tests for pkg/buffer implementations

The repo has multiple buffer implementations (elastic_ring_buffer, elastic_ring_list_buffer, linked_list_buffer, ring_buffer) with some unit tests, but they appear platform-agnostic and lack integrated stress tests. Add comprehensive cross-platform buffer tests to verify correctness under concurrent access patterns that gnet's event loops would create.

  • [ ] Create pkg/buffer/buffer_stress_test.go testing all buffer types under concurrent read/write patterns
  • [ ] Add benchmarks comparing buffer types (elastic vs ring vs linked list) for gnet's use cases
  • [ ] Test buffer behavior with the actual event loop in eventloop_unix_test.go and eventloop_windows.go patterns
  • [ ] Verify memory usage and GC pressure across buffer implementations under sustained traffic

🌿Good first issues

  • idea: Add cross-platform benchmarks in a new examples/benchmarks/ directory comparing gnet vs net package on Windows (os_windows_test.go exists but has no comprehensive throughput benchmarks)
  • idea: Write integration tests for conn_matrix_test.go covering edge cases like connection ID wraparound and matrix resizing under concurrent load (current tests only check basic ops)
  • idea: Document the callback handler blocking behavior and add a NonBlockingOnData example in pkg/ showing how to safely dispatch to a worker pool (ants v2 is already imported but no example exists)

⭐Top contributors

Click to expand

πŸ“Recent commits

Click to expand
  • b614054 β€” chore: use my referral link of DO (panjf2000)
  • 91cf015 β€” ci: bump up Go version to 1.26 (#755) (panjf2000)
  • 0c3e6f8 β€” bug: switch to socket.Dup in eventloop.enroll to enable close-on-exec (#745) (panjf2000)
  • 58d255f β€” bug: set FD_CLOEXEC flag when enrolling a client FD (#743) (gunli)
  • 0dd70fc β€” chore: fix some typos (panjf2000)
  • a46e1e7 β€” opt: use sync.Once to ensure listener opens only once (#739) (panjf2000)
  • 0dc6dc2 β€” Optimize next highest power of two calculation (#737) (dxasu)
  • e0d20dc β€” pkg/ring/ring_buffer: remove the unused field "bs" (#736) (dxasu)
  • bb3464e β€” bug: fix Unix address parsing absolute path (#731) (panjf2000)
  • 1e690fc β€” test: add more tests for bad network addresses (#729) (panjf2000)

πŸ”’Security observations

The gnet networking framework demonstrates generally good security practices with a focus on performance-critical, platform-specific implementations. Primary concerns include: (1) Outdated minimum Go version (1.20 is EOL), which should be updated to receive security patches; (2) Custom buffer and connection management code that requires careful verification to prevent race conditions and buffer misuse; (3) Platform-specific implementations across multiple operating systems that each require individual security auditing; (4) Lack of visible input validation patterns, though the library is low-level and may delegate this to consumers. The codebase lacks obvious secrets or injection vulnerabilities, and dependencies are relatively minimal and well-maintained. Recommendation: Update Go version, run comprehensive race condition testing, conduct platform-specific security audits, and integrate static analysis tools (gosec, staticcheck) into CI/CD.

  • Medium Β· Outdated Go Version Requirement β€” go.mod (go 1.20). The project specifies Go 1.20 as the minimum version. Go 1.20 reached end-of-life in August 2024. Using outdated Go versions may expose the codebase to known security vulnerabilities that have been patched in newer releases. Fix: Update the minimum Go version to 1.23 or later. Ensure all dependencies are compatible with the newer version and run full test suite.
  • Low Β· Potential Race Condition in Connection Handling β€” conn_map.go, conn_matrix.go, connection_*.go files. The codebase contains multiple platform-specific implementations (conn_matrix.go, conn_map.go, connection_*.go) for handling concurrent connections. Without reviewing the actual implementation details, concurrent map access or non-atomic operations could lead to race conditions in high-concurrency scenarios. Fix: Run the codebase with '-race' flag during testing: go test -race ./.... Ensure all shared state access is properly synchronized using mutexes or atomic operations.
  • Low Β· Platform-Specific Code Paths Not Fully Visible β€” acceptor_*.go, connection_*.go, engine_*.go, eventloop_*.go, listener_*.go, client_*.go files. The project has multiple platform-specific implementations (Unix, Windows, BSD, Linux). Without visibility into the actual code content, potential platform-specific vulnerabilities in syscall usage, file descriptor handling, or networking primitives cannot be fully assessed. Fix: Conduct thorough code review of all platform-specific syscall usage. Use tools like 'gosec' to identify unsafe patterns. Test on each supported platform with network fuzzing tools.
  • Low Β· Buffer Management Security β€” pkg/buffer/ directory. The project implements custom buffer management (pkg/buffer/elastic, pkg/buffer/ring, pkg/buffer/linkedlist). Custom memory management can introduce vulnerabilities such as buffer overflows, use-after-free, or improper bounds checking if not carefully implemented. Fix: Review buffer implementation for bounds checking. Use fuzzing tools to test buffer operations with various input sizes. Consider using proven third-party buffer libraries where applicable.
  • Low Β· External Dependency: github.com/valyala/bytebufferpool β€” go.mod (github.com/valyala/bytebufferpool v1.0.0). The bytebufferpool package is a convenience dependency that reuses buffers. While generally safe, ensure its usage pattern doesn't lead to buffer reuse vulnerabilities where sensitive data might persist across requests. Fix: Verify that buffers containing sensitive data are explicitly cleared before being returned to the pool. Consider implementing a custom buffer clearing mechanism.

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals β€” see the live page for receipts. Re-run on a new commit to refresh.

Healthy signals Β· panjf2000/gnet β€” RepoPilot