Wrap server-side panics in EREMOTEIO.

EREMOTEIO is a more appropriate generic error for a remote procedure call (RPC)
failure on the gofer. EFAULT means bad address and can be misleading to the
application as it will denote a MM layer related issue.

PiperOrigin-RevId: 423990374
This commit is contained in:
Ayush Ranjan
2022-01-24 22:01:10 -08:00
committed by gVisor bot
parent 06ffd8eaa6
commit f3ff82093e
3 changed files with 21 additions and 6 deletions
+17 -2
View File
@@ -15,6 +15,8 @@
package lisafs
import (
"runtime/debug"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/flipcall"
"gvisor.dev/gvisor/pkg/log"
@@ -156,7 +158,7 @@ func (c *Connection) respondError(comm Communicator, err unix.Errno) (MID, uint3
return Error, respLen, nil
}
func (c *Connection) handleMsg(comm Communicator, m MID, payloadLen uint32) (MID, uint32, []int) {
func (c *Connection) handleMsg(comm Communicator, m MID, payloadLen uint32) (retM MID, retPayloadLen uint32, retFDs []int) {
if payloadLen > c.maxMessageSize {
log.Warningf("received payload is too large: %d bytes", payloadLen)
return c.respondError(comm, unix.EIO)
@@ -165,7 +167,20 @@ func (c *Connection) handleMsg(comm Communicator, m MID, payloadLen uint32) (MID
// c.close() has been called; the connection is shutting down.
return c.respondError(comm, unix.ECONNRESET)
}
defer c.reqGate.Leave()
defer func() {
c.reqGate.Leave()
// Don't allow a panic to propagate.
if err := recover(); err != nil {
// Include a useful log message.
log.Warningf("panic in handler: %v\n%s", err, debug.Stack())
// Wrap in an EREMOTEIO error; we don't really have a better way to
// describe this kind of error. EREMOTEIO is appropriate for a generic
// failed RPC message.
retM, retPayloadLen, retFDs = c.respondError(comm, unix.EREMOTEIO)
}
}()
if !c.mounted && m != Mount {
log.Warningf("connection must first be mounted")
+2 -2
View File
@@ -45,8 +45,8 @@ func TestPanic(t *testing.T) {
})
// Attach to the client.
if _, err := c.Attach("/"); err != unix.EFAULT {
t.Fatalf("got attach err %v, want EFAULT", err)
if _, err := c.Attach("/"); err != unix.EREMOTEIO {
t.Fatalf("got attach err %v, want EREMOTEIO", err)
}
}
+2 -2
View File
@@ -494,10 +494,10 @@ func (cs *connState) handle(m message) (r message) {
// Include a useful log message.
log.Warningf("panic in handler: %v\n%s", err, debug.Stack())
// Wrap in an EFAULT error; we don't really have a
// Wrap in an EREMOTEIO error; we don't really have a
// better way to describe this kind of error. It will
// usually manifest as a result of the test framework.
r = newErrFromLinuxerr(linuxerr.EFAULT)
r = newErrFromLinuxerr(linuxerr.EREMOTEIO)
}
}()
if handler, ok := m.(handler); ok {