Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit ffa35a9

Browse files
committed
Clean up connections after websocket close
Make sure we clean up connections by just going through the map and cleaning all the verkeys that match the connection. This is a suboptimal solution, but a connection close is not something happennig often. Signed-off-by: Boran Car <boran.car@gmail.com>
1 parent a66828f commit ffa35a9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pkg/didcomm/transport/ws/pool.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func (d *connPool) remove(verKey string) {
7979
}
8080

8181
func (d *connPool) listener(conn *websocket.Conn, outbound bool) {
82-
verKeys := []string{}
83-
84-
defer d.close(conn, verKeys)
82+
defer d.close(conn)
8583

8684
go keepConnAlive(conn, outbound, pingFrequency)
8785

@@ -154,14 +152,25 @@ func (d *connPool) addKey(unpackMsg *transport.Envelope, trans *decorator.Transp
154152
}
155153
}
156154

157-
func (d *connPool) close(conn *websocket.Conn, verKeys []string) {
155+
func (d *connPool) close(conn *websocket.Conn) {
158156
if err := conn.Close(websocket.StatusNormalClosure,
159157
"closing the connection"); websocket.CloseStatus(err) != websocket.StatusNormalClosure {
160158
logger.Errorf("connection close error")
161159
}
162160

163-
for _, v := range verKeys {
164-
d.remove(v)
161+
d.Lock()
162+
defer d.Unlock()
163+
164+
var toRemove []string
165+
166+
for k, v := range d.connMap {
167+
if v == conn {
168+
toRemove = append(toRemove, k)
169+
}
170+
}
171+
172+
for _, v := range toRemove {
173+
delete(d.connMap, v)
165174
}
166175
}
167176

0 commit comments

Comments
 (0)