Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race cond #32

Open
wants to merge 1 commit into
base: release_v1.1.3
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
17 changes: 15 additions & 2 deletions connwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows
// +build !windows

package grpcfd
Expand Down Expand Up @@ -72,6 +73,7 @@ type connWrap struct {
sendFDs []int
errChs []chan error
sendExecutor serialize.Executor
closed bool

recvFDChans map[inodeKey][]chan uintptr
recvedFDs map[inodeKey]uintptr
Expand Down Expand Up @@ -126,6 +128,7 @@ func (w *connWrap) close() error {
w.sendFDs = nil
w.errChs = nil
})
w.closed = true
})
return err
}
Expand Down Expand Up @@ -180,6 +183,10 @@ func (w *connWrap) SendFD(fd uintptr) <-chan error {
return errCh
}
w.sendExecutor.AsyncExec(func() {
if w.closed {
close(errCh)
return
}
w.sendFDs = append(w.sendFDs, int(fd))
w.errChs = append(w.errChs, errCh)
})
Expand Down Expand Up @@ -231,6 +238,10 @@ func (w *connWrap) String() string {
func (w *connWrap) RecvFD(dev, ino uint64) <-chan uintptr {
fdCh := make(chan uintptr, 1)
w.recvExecutor.AsyncExec(func() {
if w.closed {
close(fdCh)
return
}
key := inodeKey{
dev: dev,
ino: ino,
Expand Down Expand Up @@ -352,14 +363,16 @@ func (w *connWrap) Read(b []byte) (n int, err error) {
}

// FromPeer - return grpcfd.FDTransceiver from peer.Peer
// ok is true of successful, false otherwise
//
// ok is true of successful, false otherwise
func FromPeer(p *peer.Peer) (transceiver FDTransceiver, ok bool) {
transceiver, ok = p.Addr.(FDTransceiver)
return transceiver, ok
}

// FromContext - return grpcfd.FDTransceiver from context.Context
// ok is true of successful, false otherwise
//
// ok is true of successful, false otherwise
func FromContext(ctx context.Context) (transceiver FDTransceiver, ok bool) {
p, ok := peer.FromContext(ctx)
if !ok {
Expand Down
Loading