berty / go-orbit-db

Go version of P2P Database on IPFS
https://berty.tech
Apache License 2.0
412 stars 56 forks source link

Missing mutex unlock in channelHolder.incomingConnHandler() #64

Closed phanhuynhquy closed 4 years ago

phanhuynhquy commented 4 years ago

Found small issue when review in below function when stream's protocol is not registered before

func (h *channelHolder) incomingConnHandler(stream network.Stream) {
    h.muExpected.Lock()

    ch, ok := h.expectedPID[stream.Protocol()]
    if !ok {
                // => Missing unlock in this case
        return
    }

    h.muExpected.Unlock()

    ch <- stream
}

Also consider function (c *channel) Send(ctx context.Context, bytes []byte) There is no mutex to protect in between two writes :

        if _, err := stream.Write(b); err != nil {
        return err
    }

    _, err := stream.Write(bytes)
    return err
phanhuynhquy commented 4 years ago

fixed at https://github.com/berty/go-orbit-db/pull/67