mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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")
|
||||
|
||||
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user