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

Commit 4094d54

Browse files
committed
Move close channel routines after connection closed
1 parent 0a364da commit 4094d54

10 files changed

+37
-27
lines changed

access_validator.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package ws
22

33
import (
44
"bytes"
5-
"github.com/spiral/roadrunner/service/http/attributes"
65
"io"
76
"net/http"
87
"strings"
8+
9+
"github.com/spiral/roadrunner/service/http/attributes"
910
)
1011

1112
type accessValidator struct {

access_validator_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ws
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestResponseWrapper_Body(t *testing.T) {

cmd/rr-ws/ws/debug.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package ws
22

33
import (
4+
"strings"
5+
46
"github.com/gorilla/websocket"
57
"github.com/sirupsen/logrus"
68
"github.com/spf13/cobra"
79
ws "github.com/spiral/broadcast-ws"
810
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
911
"github.com/spiral/roadrunner/cmd/util"
10-
"strings"
1112
)
1213

1314
func init() {

config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package ws
22

33
import (
44
"encoding/json"
5+
"testing"
6+
57
"github.com/spiral/roadrunner/service"
68
"github.com/stretchr/testify/assert"
7-
"testing"
89
)
910

1011
type mockCfg struct{ cfg string }

conn_context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package ws
22

33
import (
44
"encoding/json"
5+
56
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
7+
"github.com/spiral/broadcast/v2"
78
)
89

910
// ConnContext carries information about websocket connection and it's topics.

conn_context_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ws
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestConnContext_ManageTopics(t *testing.T) {

conn_pool.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package ws
22

33
import (
44
"errors"
5-
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
75
"sync"
6+
7+
"github.com/gorilla/websocket"
8+
"github.com/spiral/broadcast/v2"
89
)
910

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

119-
delete(cp.conns, conn)
120-
close(ctx.upstream)
121120
if err := conn.Close(); err != nil {
122121
cp.errHandler(err, conn)
123122
}
123+
124+
delete(cp.conns, conn)
125+
close(ctx.upstream)
124126
}
125127
}

go.mod

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module github.com/spiral/broadcast-ws
22

3-
go 1.12
3+
go 1.15
44

55
require (
66
github.com/gorilla/websocket v1.4.1
7-
github.com/prometheus/client_golang v1.2.1 // indirect
7+
github.com/prometheus/client_golang v1.5.0
88
github.com/sirupsen/logrus v1.4.2
9-
github.com/spf13/cobra v0.0.5 // indirect
10-
github.com/spiral/broadcast v0.0.0-20191206140608-766959683e74
11-
github.com/spiral/roadrunner v1.5.2
12-
github.com/stretchr/testify v1.3.0
9+
github.com/spf13/cobra v0.0.6
10+
github.com/spiral/broadcast/v2 v2.0.5-beta1
11+
github.com/spiral/roadrunner v1.6.4
12+
github.com/stretchr/testify v1.5.1
1313
)

service.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package ws
22

33
import (
44
"encoding/json"
5+
"net/http"
6+
"sync"
7+
"sync/atomic"
8+
59
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
10+
"github.com/spiral/broadcast/v2"
711
"github.com/spiral/roadrunner/service/env"
812
rhttp "github.com/spiral/roadrunner/service/http"
913
"github.com/spiral/roadrunner/service/rpc"
10-
"net/http"
11-
"sync"
12-
"sync/atomic"
1314
)
1415

1516
// ID defines service id.

service_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package ws
22

33
import (
44
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
"net/url"
8+
"strings"
9+
"testing"
10+
"time"
11+
512
"github.com/gorilla/websocket"
613
"github.com/sirupsen/logrus"
714
"github.com/sirupsen/logrus/hooks/test"
8-
"github.com/spiral/broadcast"
15+
"github.com/spiral/broadcast/v2"
916
"github.com/spiral/roadrunner/service"
1017
"github.com/spiral/roadrunner/service/env"
1118
rrhttp "github.com/spiral/roadrunner/service/http"
1219
"github.com/spiral/roadrunner/service/rpc"
1320
"github.com/stretchr/testify/assert"
14-
"io/ioutil"
15-
"net/http"
16-
"net/url"
17-
"strings"
18-
"testing"
19-
"time"
2021
)
2122

2223
type testCfg struct {

0 commit comments

Comments
 (0)