Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Move close channel routines after connection closed
Browse files Browse the repository at this point in the history
  • Loading branch information
rustatian committed Jan 26, 2021
1 parent 0a364da commit 4094d54
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 27 deletions.
3 changes: 2 additions & 1 deletion access_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package ws

import (
"bytes"
"github.com/spiral/roadrunner/service/http/attributes"
"io"
"net/http"
"strings"

"github.com/spiral/roadrunner/service/http/attributes"
)

type accessValidator struct {
Expand Down
3 changes: 2 additions & 1 deletion access_validator_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ws

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestResponseWrapper_Body(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/rr-ws/ws/debug.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package ws

import (
"strings"

"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
ws "github.com/spiral/broadcast-ws"
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
"github.com/spiral/roadrunner/cmd/util"
"strings"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ws

import (
"encoding/json"
"testing"

"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
"testing"
)

type mockCfg struct{ cfg string }
Expand Down
3 changes: 2 additions & 1 deletion conn_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package ws

import (
"encoding/json"

"github.com/gorilla/websocket"
"github.com/spiral/broadcast"
"github.com/spiral/broadcast/v2"
)

// ConnContext carries information about websocket connection and it's topics.
Expand Down
3 changes: 2 additions & 1 deletion conn_context_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ws

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConnContext_ManageTopics(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ws

import (
"errors"
"github.com/gorilla/websocket"
"github.com/spiral/broadcast"
"sync"

"github.com/gorilla/websocket"
"github.com/spiral/broadcast/v2"
)

// manages a set of websocket connections
Expand Down Expand Up @@ -116,10 +117,11 @@ func (cp *connPool) close() {
cp.errHandler(err, conn)
}

delete(cp.conns, conn)
close(ctx.upstream)
if err := conn.Close(); err != nil {
cp.errHandler(err, conn)
}

delete(cp.conns, conn)
close(ctx.upstream)
}
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/spiral/broadcast-ws

go 1.12
go 1.15

require (
github.com/gorilla/websocket v1.4.1
github.com/prometheus/client_golang v1.2.1 // indirect
github.com/prometheus/client_golang v1.5.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5 // indirect
github.com/spiral/broadcast v0.0.0-20191206140608-766959683e74
github.com/spiral/roadrunner v1.5.2
github.com/stretchr/testify v1.3.0
github.com/spf13/cobra v0.0.6
github.com/spiral/broadcast/v2 v2.0.5-beta1
github.com/spiral/roadrunner v1.6.4
github.com/stretchr/testify v1.5.1
)
9 changes: 5 additions & 4 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package ws

import (
"encoding/json"
"net/http"
"sync"
"sync/atomic"

"github.com/gorilla/websocket"
"github.com/spiral/broadcast"
"github.com/spiral/broadcast/v2"
"github.com/spiral/roadrunner/service/env"
rhttp "github.com/spiral/roadrunner/service/http"
"github.com/spiral/roadrunner/service/rpc"
"net/http"
"sync"
"sync/atomic"
)

// ID defines service id.
Expand Down
15 changes: 8 additions & 7 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package ws

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"strings"
"testing"
"time"

"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/broadcast"
"github.com/spiral/broadcast/v2"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/env"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/spiral/roadrunner/service/rpc"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/url"
"strings"
"testing"
"time"
)

type testCfg struct {
Expand Down

0 comments on commit 4094d54

Please sign in to comment.