{"id":13581873,"url":"https://github.com/tevino/tcp-shaker","last_synced_at":"2025-04-06T10:33:00.920Z","repository":{"id":8890455,"uuid":"60079724","full_name":"tevino/tcp-shaker","owner":"tevino","description":":heartbeat: Perform TCP handshake without ACK in Go, useful for health check, that is SYN, SYN-ACK, RST.","archived":false,"fork":false,"pushed_at":"2024-01-03T09:47:55.000Z","size":71,"stargazers_count":412,"open_issues_count":5,"forks_count":56,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-14T21:42:29.757Z","etag":null,"topics":["ack","go","golang","golang-library","golang-package","handshake","haproxy","health-check","linux","network","packets","tcp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tevino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-31T10:19:07.000Z","updated_at":"2024-10-25T16:01:12.000Z","dependencies_parsed_at":"2024-01-03T10:44:53.533Z","dependency_job_id":"7e0c7673-1fd2-491b-aa1c-171d745d2b04","html_url":"https://github.com/tevino/tcp-shaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevino%2Ftcp-shaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevino%2Ftcp-shaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevino%2Ftcp-shaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevino%2Ftcp-shaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tevino","download_url":"https://codeload.github.com/tevino/tcp-shaker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247470538,"owners_count":20944146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ack","go","golang","golang-library","golang-package","handshake","haproxy","health-check","linux","network","packets","tcp"],"created_at":"2024-08-01T15:02:17.445Z","updated_at":"2025-04-06T10:33:00.297Z","avatar_url":"https://github.com/tevino.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# TCP Checker :heartbeat:\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/tevino/tcp-shaker)](https://goreportcard.com/report/github.com/tevino/tcp-shaker)\n[![GoDoc](https://godoc.org/github.com/tevino/tcp-shaker?status.svg)](https://godoc.org/github.com/tevino/tcp-shaker)\n[![Build Status](https://travis-ci.org/tevino/tcp-shaker.svg?branch=master)](https://travis-ci.org/tevino/tcp-shaker)\n\nThis package is used to perform TCP handshake without ACK, which useful for TCP health checking.\n\nHAProxy does this exactly the same, which is:\n\n1. SYN\n2. SYN-ACK\n3. RST\n\nThis implementation has been running on tens of thousands of production servers for years.\n\n## Why do I have to do this\n\nIn most cases when you establish a TCP connection(e.g. via `net.Dial`), these are the first three packets between the client and server([TCP three-way handshake][tcp-handshake]):\n\n1. Client -\u003e Server: SYN\n2. Server -\u003e Client: SYN-ACK\n3. Client -\u003e Server: ACK\n\n**This package tries to avoid the last ACK when doing handshakes.**\n\nBy sending the last ACK, the connection is considered established.\n\nHowever, as for TCP health checking the server could be considered alive right after it sends back SYN-ACK,\n\nthat renders the last ACK unnecessary or even harmful in some cases.\n\n### Benefits\n\nBy avoiding the last ACK\n\n1. Less packets better efficiency\n2. The health checking is less obvious\n\nThe second one is essential because it bothers the server less.\n\nThis means the application level server will not notice the health checking traffic at all, **thus the act of health checking will not be\nconsidered as some misbehavior of client.**\n\n## Requirements\n\n- Linux 2.4 or newer\n\nThere is a **fake implementation** for **non-Linux** platform which is equivalent to:\n\n```go\nconn, err := net.DialTimeout(\"tcp\", addr, timeout)\nconn.Close()\n```\n\nThe reason for a fake implementation is that there is currently no way to perform an equivalent operation on certain platforms, specifically macOS. A fake implementation is a degradation on those platforms and ensures a successful compilation.\n\n\n## Usage\n\n```go\nimport \"github.com/tevino/tcp-shaker\"\n\n// Initializing the checker\n// It is expected to be shared among goroutines, only one instance is necessary.\nc := NewChecker()\n\nctx, stopChecker := context.WithCancel(context.Background())\ndefer stopChecker()\ngo func() {\n\tif err := c.CheckingLoop(ctx); err != nil {\n\t\tfmt.Println(\"checking loop stopped due to fatal error: \", err)\n\t}\n}()\n\n\u003c-c.WaitReady()\n\n// Checking google.com\n\ntimeout := time.Second * 1\nerr := c.CheckAddr(\"google.com:80\", timeout)\nswitch err {\ncase ErrTimeout:\n\tfmt.Println(\"Connect to Google timed out\")\ncase nil:\n\tfmt.Println(\"Connect to Google succeeded\")\ndefault:\n\tfmt.Println(\"Error occurred while connecting: \", err)\n}\n```\n\n## TODO\n\n- [x] IPv6 support (Test environment needed, PRs are welcome)\n\n## Special thanks to contributors\n\n- @lujjjh Added zero linger support for non-Linux platform\n- @jakubgs Fixed compatibility on Android\n- @kirk91 Added support for IPv6\n\n[tcp-handshake]: https://en.wikipedia.org/wiki/Handshaking#TCP_three-way_handshake\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftevino%2Ftcp-shaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftevino%2Ftcp-shaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftevino%2Ftcp-shaker/lists"}