containerd / ttrpc

GRPC for low-memory environments
Apache License 2.0
558 stars 80 forks source link

Add recvClose channel to stream #140

Closed dmcgowan closed 1 year ago

dmcgowan commented 1 year ago

Prevent panic from closing recv channel, which may be written to after close. Use a separate channel to signal recv has closed and check that channel on read and write.

Alternative to #139 for https://github.com/containerd/containerd/issues/8390

dmcgowan commented 1 year ago

Had to add additional

    select {
    case <-s.recvClose:
        return s.recvErr
    default:
    }

on receive to replace the err nil check. Since Go does not guarantee select order priority, messages could still be sent after a close was called, causing that test flake. If the receive and close happen at the same time, it isn't important which one wins.