CloseErrors should cause fRPC to Close the underlying connection
Closed this issue · 0 comments
ShivanshVij commented
Currently, returning an error from an fRPC handler does not close the underlying connection. This default behaviour is fine.
However, users should be able to return a special CloseError
type - which will close the underlying connection once the error has been written.
An example implementation the CloseError
type CloseError struct {
err error
}
func NewCloseError(err error) CloseError {
return CloseError{err: err}
}
func (e CloseError) Error() string {
return e.err.Error()
}
And in the generated fRPC Code, an example check:
table[10] = func(ctx context.Context, incoming *packet.Packet) (outgoing *packet.Packet, action frisbee.Action) {
req := NewProxyRequest()
err := req.Decode((*incoming.Content)[:incoming.Metadata.ContentLength])
if err == nil {
if req.ignore {
controller.Proxy(ctx, req)
} else {
var res *ProxyResponse
outgoing = incoming
outgoing.Content.Reset()
res, err = controller.Proxy(ctx, req)
if err != nil {
if _, ok := err.(CloseError); ok {
action = frisbee.CLOSE
}
res.Error(outgoing.Content, err)
} else {
res.Encode(outgoing.Content)
}
outgoing.Metadata.ContentLength = uint32(len(*outgoing.Content))
}
}
return
}