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

Clean up connections after websocket close #3352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions pkg/didcomm/transport/ws/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ func (d *connPool) remove(verKey string) {
}

func (d *connPool) listener(conn *websocket.Conn, outbound bool) {
verKeys := []string{}
Copy link
Contributor Author

@borancar borancar Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These never get populated.


defer d.close(conn, verKeys)
defer d.close(conn)

go keepConnAlive(conn, outbound, pingFrequency)

Expand Down Expand Up @@ -154,14 +152,25 @@ func (d *connPool) addKey(unpackMsg *transport.Envelope, trans *decorator.Transp
}
}

func (d *connPool) close(conn *websocket.Conn, verKeys []string) {
func (d *connPool) close(conn *websocket.Conn) {
if err := conn.Close(websocket.StatusNormalClosure,
"closing the connection"); websocket.CloseStatus(err) != websocket.StatusNormalClosure {
logger.Errorf("connection close error")
}

for _, v := range verKeys {
d.remove(v)
d.Lock()
defer d.Unlock()

var toRemove []string

for k, v := range d.connMap {
if v == conn {
toRemove = append(toRemove, k)
}
}

for _, v := range toRemove {
delete(d.connMap, v)
}
}

Expand Down