diff options
author | Valery Piashchynski <[email protected]> | 2021-05-30 19:35:28 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-05-30 19:36:18 +0300 |
commit | 0ee91dc24d3e68706d89092c06b1c0d09dab0353 (patch) | |
tree | b4699fc334ba7b13be475d54021d980960cff991 /plugins/websockets | |
parent | 8188b34646e29861071ab5270160a9665eb1832f (diff) |
- Do not use response.writer in hijacked connection
- Remove atomics from the ws
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/websockets')
-rw-r--r-- | plugins/websockets/plugin.go | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/plugins/websockets/plugin.go b/plugins/websockets/plugin.go index b3495e77..c51c7ca1 100644 --- a/plugins/websockets/plugin.go +++ b/plugins/websockets/plugin.go @@ -3,7 +3,6 @@ package websockets import ( "net/http" "sync" - "sync/atomic" "time" "github.com/fasthttp/websocket" @@ -40,7 +39,6 @@ type Plugin struct { // GO workers pool workersPool *pool.WorkersPool - stopped uint64 hub channel.Hub } @@ -61,7 +59,6 @@ func (p *Plugin) Init(cfg config.Configurer, log logger.Logger, channel channel. p.storage = storage.NewStorage() p.workersPool = pool.NewWorkersPool(p.storage, &p.connections, log) p.hub = channel - p.stopped = 0 return nil } @@ -87,7 +84,6 @@ func (p *Plugin) Serve() chan error { } func (p *Plugin) Stop() error { - atomic.AddUint64(&p.stopped, 1) p.workersPool.Stop() return nil } @@ -123,11 +119,6 @@ func (p *Plugin) Middleware(next http.Handler) http.Handler { return } - if atomic.CompareAndSwapUint64(&p.stopped, 1, 1) { - // plugin stopped - return - } - r = attributes.Init(r) err := validator.NewValidator().AssertServerAccess(p.hub, r) @@ -156,7 +147,8 @@ func (p *Plugin) Middleware(next http.Handler) http.Handler { // upgrade connection to websocket connection _conn, err := upgraded.Upgrade(w, r, nil) if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + // connection hijacked, do not use response.writer or request + p.log.Error("upgrade connection error", "error", err) return } |