Skip to content

Commit

Permalink
Prevent multiclient panic if underlying client is closed
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed May 19, 2020
1 parent 5a50fba commit af72bb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 7 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,13 @@ func (c *Client) handleMessage(msgType int, data []byte) error {
data = nil
}

var msg *Message
switch payload.Type {
case payloads.BINARY, payloads.TEXT, payloads.SESSION:
msg = &Message{
Src: inboundMsg.Src,
Data: data,
Type: int32(payload.Type),
Encrypted: payloadMsg.Encrypted,
MessageID: payload.MessageId,
NoReply: payload.NoReply,
}
msg := &Message{
Src: inboundMsg.Src,
Data: data,
Type: int32(payload.Type),
Encrypted: payloadMsg.Encrypted,
MessageID: payload.MessageId,
NoReply: payload.NoReply,
}

if len(payload.ReplyToId) > 0 {
Expand Down
10 changes: 8 additions & 2 deletions multiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,18 @@ func NewMultiClient(account *Account, baseIdentifier string, numSubClients int,

wg.Done()

node := <-client.OnConnect.C
node, ok := <-client.OnConnect.C
if !ok {
return
}
m.OnConnect.receive(node)

for {
select {
case msg := <-client.OnMessage.C:
case msg, ok := <-client.OnMessage.C:
if !ok {
return
}
if msg.Type == SessionType {
if !msg.Encrypted {
continue
Expand Down

0 comments on commit af72bb3

Please sign in to comment.