From b75eaf3c161b56cd4bfc99a5e68c2ce3695e87b2 Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Thu, 7 Jul 2022 17:25:03 +0300 Subject: [PATCH 1/5] fix keepalive simple patch for keepalive on the same host --- recws.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recws.go b/recws.go index 4faa7af..83482bb 100644 --- a/recws.go +++ b/recws.go @@ -409,7 +409,8 @@ func (rc *RecConn) keepAlive() { } <-ticker.C - if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout() { + timeoutOffset := time.Millisecond * 10 + if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout()+timeoutOffset { rc.CloseAndReconnect() return } From 6c6a4a0ded0ecc37010d4a40518694db2806f189 Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Thu, 7 Jul 2022 17:29:43 +0300 Subject: [PATCH 2/5] Update recws.go --- recws.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recws.go b/recws.go index 83482bb..4b6aebe 100644 --- a/recws.go +++ b/recws.go @@ -409,7 +409,7 @@ func (rc *RecConn) keepAlive() { } <-ticker.C - timeoutOffset := time.Millisecond * 10 + timeoutOffset := time.Millisecond * 50 if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout()+timeoutOffset { rc.CloseAndReconnect() return From a25330e8f2fef51d267cb4b791b3bdd79ae9d9b8 Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Thu, 7 Jul 2022 18:26:50 +0300 Subject: [PATCH 3/5] Update recws.go --- recws.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recws.go b/recws.go index 4b6aebe..36ee7d7 100644 --- a/recws.go +++ b/recws.go @@ -409,7 +409,7 @@ func (rc *RecConn) keepAlive() { } <-ticker.C - timeoutOffset := time.Millisecond * 50 + timeoutOffset := time.Millisecond * 500 if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout()+timeoutOffset { rc.CloseAndReconnect() return From dd31a10749f04ffe17f39d8bc4e1d739327218f1 Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Fri, 12 Aug 2022 01:57:40 +0300 Subject: [PATCH 4/5] make Close more atomic --- recws.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/recws.go b/recws.go index 36ee7d7..5bd82b1 100644 --- a/recws.go +++ b/recws.go @@ -82,13 +82,12 @@ func (rc *RecConn) getConn() *websocket.Conn { // Close closes the underlying network connection without // sending or waiting for a close frame. func (rc *RecConn) Close() { - if rc.getConn() != nil { - rc.mu.Lock() + rc.mu.Lock() + if rc.Conn != nil { rc.Conn.Close() - rc.mu.Unlock() } - - rc.setIsConnected(false) + rc.isConnected = false + rc.mu.Unlock() } // Shutdown gracefully closes the connection by sending the websocket.CloseMessage. From aff7096e603b6c0a2306e2ebe200a9d68a9a701b Mon Sep 17 00:00:00 2001 From: Nikolay Pavlovich Date: Sun, 4 Sep 2022 02:06:46 +0300 Subject: [PATCH 5/5] change repo --- README.md | 8 +++++--- examples/basic.go | 3 ++- go.mod | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 36d7c2a..c5a5b3e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ # recws +***This is fork of [recws-org/recws](https://github.com/recws-org/recws) with some fixes*** + Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https://github.com/gorilla/websocket) that will automatically reconnect if the connection is dropped - thread safe! [![Build Status](https://travis-ci.com/recws-org/recws.svg?branch=master)](https://travis-ci.com/recws-org/recws) @@ -12,7 +14,7 @@ Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https: ## Installation ```bash -go get github.com/recws-org/recws +go get github.com/nikepan/recws ``` ## Sponsors @@ -21,8 +23,8 @@ go get github.com/recws-org/recws ## Logo -- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx) -- Gopher by [Gophers](https://github.com/egonelbre/gophers) +- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx) +- Gopher by [Gophers](https://github.com/egonelbre/gophers) ## License diff --git a/examples/basic.go b/examples/basic.go index a234ad0..4a8df37 100644 --- a/examples/basic.go +++ b/examples/basic.go @@ -2,9 +2,10 @@ package main import ( "context" - "github.com/recws-org/recws" "log" "time" + + "github.com/nikepan/recws" ) func main() { diff --git a/go.mod b/go.mod index 5f8b11d..047a5bd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/recws-org/recws +module github.com/nikepan/recws -go 1.17 +go 1.18 require ( github.com/gorilla/websocket v1.4.2