From b941e357615a7b0e04dbf6535cafacfbb4b7e276 Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Fri, 4 Oct 2019 14:55:11 -0700 Subject: Return EIO from p9 if flipcall.Endpoint.Connect() fails. Also ensure that all flipcall transport errors not returned by p9 (converted to EIO by the client, or dropped on the floor by channel server goroutines) are logged. PiperOrigin-RevId: 272963663 --- pkg/p9/client.go | 23 +++++++++++++++++++---- pkg/p9/server.go | 4 +++- pkg/p9/transport_flipcall.go | 24 ++---------------------- 3 files changed, 24 insertions(+), 27 deletions(-) (limited to 'pkg') diff --git a/pkg/p9/client.go b/pkg/p9/client.go index 2412aa5e1..221516c6c 100644 --- a/pkg/p9/client.go +++ b/pkg/p9/client.go @@ -505,12 +505,27 @@ func (c *Client) sendRecvChannel(t message, r message) error { ch.active = false c.channelsMu.Unlock() c.channelsWg.Done() - return err + // Map all transport errors to EIO, but ensure that the real error + // is logged. + log.Warningf("p9.Client.sendRecvChannel: flipcall.Endpoint.Connect: %v", err) + return syscall.EIO } } - // Send the message. - err := ch.sendRecv(c, t, r) + // Send the request and receive the server's response. + rsz, err := ch.send(t) + if err != nil { + // See above. + c.channelsMu.Lock() + ch.active = false + c.channelsMu.Unlock() + c.channelsWg.Done() + log.Warningf("p9.Client.sendRecvChannel: p9.channel.send: %v", err) + return syscall.EIO + } + + // Parse the server's response. + _, retErr := ch.recv(r, rsz) // Release the channel. c.channelsMu.Lock() @@ -523,7 +538,7 @@ func (c *Client) sendRecvChannel(t message, r message) error { c.channelsMu.Unlock() c.channelsWg.Done() - return err + return retErr } // Version returns the negotiated 9P2000.L.Google version number. diff --git a/pkg/p9/server.go b/pkg/p9/server.go index 69c886a5d..e717e6161 100644 --- a/pkg/p9/server.go +++ b/pkg/p9/server.go @@ -452,7 +452,9 @@ func (cs *connState) initializeChannels() (err error) { cs.channelWg.Add(1) go func() { // S/R-SAFE: Server side. defer cs.channelWg.Done() - res.service(cs) + if err := res.service(cs); err != nil { + log.Warningf("p9.channel.service: %v", err) + } }() } diff --git a/pkg/p9/transport_flipcall.go b/pkg/p9/transport_flipcall.go index 7cdf4ecc3..233f825e3 100644 --- a/pkg/p9/transport_flipcall.go +++ b/pkg/p9/transport_flipcall.go @@ -132,7 +132,7 @@ func (ch *channel) send(m message) (uint32, error) { if filer, ok := m.(filer); ok { if f := filer.FilePayload(); f != nil { if err := ch.fds.SendFD(f.FD()); err != nil { - return 0, syscall.EIO // Map everything to EIO. + return 0, err } f.Close() // Per sendRecvLegacy. sentFD = true // To mark below. @@ -162,15 +162,7 @@ func (ch *channel) send(m message) (uint32, error) { } // Perform the one-shot communication. - n, err := ch.data.SendRecv(ssz) - if err != nil { - if n > 0 { - return n, nil - } - return 0, syscall.EIO // See above. - } - - return n, nil + return ch.data.SendRecv(ssz) } // recv decodes a message that exists on the channel. @@ -249,15 +241,3 @@ func (ch *channel) recv(r message, rsz uint32) (message, error) { return r, nil } - -// sendRecv sends the given message over the channel. -// -// This is used by the client. -func (ch *channel) sendRecv(c *Client, m, r message) error { - rsz, err := ch.send(m) - if err != nil { - return err - } - _, err = ch.recv(r, rsz) - return err -} -- cgit v1.2.3