fix: fixing memory leak from unbuffered channel
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,4 +4,4 @@ go 1.24.5
|
|||||||
|
|
||||||
require github.com/gorilla/websocket v1.5.3
|
require github.com/gorilla/websocket v1.5.3
|
||||||
|
|
||||||
require git.neurocipta.com/rogerferdinan/custom-rwmutex v1.0.0 // indirect
|
require git.neurocipta.com/rogerferdinan/custom-rwmutex v1.0.0
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ type Client struct {
|
|||||||
func NewClient(conn *websocket.Conn, subscribedPath string) *Client {
|
func NewClient(conn *websocket.Conn, subscribedPath string) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
Send: make(chan []byte, 64),
|
Send: make(chan []byte, 2),
|
||||||
SubscribedPath: subscribedPath,
|
SubscribedPath: subscribedPath,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +38,10 @@ type Hub struct {
|
|||||||
|
|
||||||
func NewHub() *Hub {
|
func NewHub() *Hub {
|
||||||
return &Hub{
|
return &Hub{
|
||||||
Broadcast: make(chan []byte),
|
Broadcast: make(chan []byte, 1),
|
||||||
Register: make(chan *Client),
|
Register: make(chan *Client, 1),
|
||||||
Unregister: make(chan *Client),
|
Unregister: make(chan *Client, 1),
|
||||||
Clients: make(map[*Client]bool),
|
Clients: make(map[*Client]bool, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func (b *SafeWebsocketClientBuilder) Build(ctx context.Context) (*SafeWebsocketC
|
|||||||
reconnectCh: make(chan struct{}, 1),
|
reconnectCh: make(chan struct{}, 1),
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
doneMap: NewSafeMap[string, chan struct{}](),
|
doneMap: NewSafeMap[string, chan struct{}](),
|
||||||
writeChan: make(chan Message),
|
writeChan: make(chan Message, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.authenticateFn != nil {
|
if b.authenticateFn != nil {
|
||||||
@@ -425,7 +425,7 @@ func (wsClient *SafeWebsocketClient) reconnectHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wsClient *SafeWebsocketClient) ReconnectChannel() <-chan struct{} {
|
func (wsClient *SafeWebsocketClient) ReconnectChannel() <-chan struct{} {
|
||||||
reconnectCh := make(chan struct{})
|
reconnectCh := make(chan struct{}, 1)
|
||||||
wsClient.mu.WriteHandler(func() error {
|
wsClient.mu.WriteHandler(func() error {
|
||||||
wsClient.reconnectChans = append(wsClient.reconnectChans, reconnectCh)
|
wsClient.reconnectChans = append(wsClient.reconnectChans, reconnectCh)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user