From 362f28344c4995daf188ab4610b6f7988fe908a4 Mon Sep 17 00:00:00 2001 From: Blake Severson Date: Wed, 8 Nov 2017 10:42:38 -0700 Subject: [PATCH 1/4] Prevent locks from becoming mutually exclusive Through some profiling under a fair amount of load, we found that on occasion the sidsLock would not release and cause channelsLock not not release as well since both are deferred. After offloading it to another goroutine, the issue subsided under load. --- server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server.go b/server.go index 7583633..907d307 100644 --- a/server.go +++ b/server.go @@ -277,7 +277,11 @@ func onDisconnectCleanup(c *Channel) { delete(c.server.rooms, c) } + + go deleteSid(c) +} +func deleteSid(c *Channel) { c.server.sidsLock.Lock() defer c.server.sidsLock.Unlock() From fba18ec5f654ed9443ab7f7ad23909ef4cd0ef54 Mon Sep 17 00:00:00 2001 From: Alexandr Mayorskiy Date: Wed, 14 Mar 2018 13:37:42 +0300 Subject: [PATCH 2/4] Change to http request --- loop.go | 2 +- server.go | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/loop.go b/loop.go index 5e73c5b..ff818df 100644 --- a/loop.go +++ b/loop.go @@ -50,7 +50,7 @@ type Channel struct { server *Server ip string - requestHeader http.Header + request *http.Request } /** diff --git a/server.go b/server.go index 7583633..3bb4cae 100644 --- a/server.go +++ b/server.go @@ -65,7 +65,14 @@ func (c *Channel) Ip() string { Get request header of this connection */ func (c *Channel) RequestHeader() http.Header { - return c.requestHeader + return c.request.Header +} + +/** +Get request +*/ +func (c *Channel) Request() *http.Request { + return c.request } /** @@ -304,7 +311,7 @@ func (s *Server) SendOpenSequence(c *Channel) { Setup event loop for given connection */ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, - requestHeader http.Header) { + r *http.Request) { interval, timeout := conn.PingParams() hdr := Header{ @@ -317,7 +324,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, c := &Channel{} c.conn = conn c.ip = remoteAddr - c.requestHeader = requestHeader + c.request = r c.initChannel() c.server = s @@ -340,7 +347,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - s.SetupEventLoop(conn, r.RemoteAddr, r.Header) + s.SetupEventLoop(conn, r.RemoteAddr, r) s.tr.Serve(w, r) } From 169ba459a401965d01357faabf408a45b6e90a89 Mon Sep 17 00:00:00 2001 From: Bruno Clermont Date: Sun, 22 Apr 2018 20:30:39 +0800 Subject: [PATCH 3/4] fix IPv6 --- client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index deded6c..32a2050 100644 --- a/client.go +++ b/client.go @@ -2,13 +2,14 @@ package gosocketio import ( "github.com/graarh/golang-socketio/transport" + "net" "strconv" ) const ( - webSocketProtocol = "ws://" + webSocketProtocol = "ws://" webSocketSecureProtocol = "wss://" - socketioUrl = "/socket.io/?EIO=3&transport=websocket" + socketioUrl = "/socket.io/?EIO=3&transport=websocket" ) /** @@ -21,7 +22,7 @@ type Client struct { /** Get ws/wss url by host and port - */ +*/ func GetUrl(host string, port int, secure bool) string { var prefix string if secure { @@ -29,7 +30,7 @@ func GetUrl(host string, port int, secure bool) string { } else { prefix = webSocketProtocol } - return prefix + host + ":" + strconv.Itoa(port) + socketioUrl + return prefix + net.JoinHostPort(host, strconv.Itoa(port)) + socketioUrl } /** From 6ad382f1250ba868aacad5ea9943f6c0ce4b409b Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 7 Aug 2018 15:10:08 +0800 Subject: [PATCH 4/4] switch to gsocket-io --- README.md | 2 +- client.go | 2 +- examples/client.go | 4 ++-- examples/server.go | 4 ++-- handler.go | 4 ++-- loop.go | 10 +++++----- send.go | 2 +- server.go | 8 ++++---- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index dde3d87..cd2123f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Examples directory contains simple client and server. ### Installation - go get github.com/graarh/golang-socketio + go get github.com/gsocket-io/golang-socketio ### Simple server usage diff --git a/client.go b/client.go index 32a2050..5aeba06 100644 --- a/client.go +++ b/client.go @@ -1,7 +1,7 @@ package gosocketio import ( - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/transport" "net" "strconv" ) diff --git a/examples/client.go b/examples/client.go index 6d1063d..9cbed61 100644 --- a/examples/client.go +++ b/examples/client.go @@ -1,8 +1,8 @@ package main import ( - "github.com/graarh/golang-socketio" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio" + "github.com/gsocket-io/golang-socketio/transport" "log" "runtime" "time" diff --git a/examples/server.go b/examples/server.go index 340949e..b0d0e88 100644 --- a/examples/server.go +++ b/examples/server.go @@ -1,8 +1,8 @@ package main import ( - "github.com/graarh/golang-socketio" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio" + "github.com/gsocket-io/golang-socketio/transport" "log" "net/http" "time" diff --git a/handler.go b/handler.go index 78c3636..6b7f6f2 100644 --- a/handler.go +++ b/handler.go @@ -2,9 +2,9 @@ package gosocketio import ( "encoding/json" - "github.com/graarh/golang-socketio/protocol" - "sync" + "github.com/gsocket-io/golang-socketio/protocol" "reflect" + "sync" ) const ( diff --git a/loop.go b/loop.go index ff818df..ebca563 100644 --- a/loop.go +++ b/loop.go @@ -3,8 +3,8 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/transport" "net/http" "sync" "time" @@ -48,9 +48,9 @@ type Channel struct { ack ackProcessor - server *Server - ip string - request *http.Request + server *Server + ip string + request *http.Request } /** diff --git a/send.go b/send.go index 07e8130..6bbb1d7 100644 --- a/send.go +++ b/send.go @@ -3,7 +3,7 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/protocol" "log" "time" ) diff --git a/server.go b/server.go index a4fd9b1..376bc51 100644 --- a/server.go +++ b/server.go @@ -7,8 +7,8 @@ import ( "encoding/json" "errors" "fmt" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/transport" "math/rand" "net/http" "sync" @@ -43,7 +43,7 @@ type Server struct { /** Close current channel - */ +*/ func (c *Channel) Close() { if c.server != nil { closeChannel(c, &c.server.methods) @@ -284,7 +284,7 @@ func onDisconnectCleanup(c *Channel) { delete(c.server.rooms, c) } - + go deleteSid(c) }