Temporary stop gap for panicking server handlers
This commit is contained in:
parent
5d88115f2a
commit
469b12ecea
@ -53,7 +53,11 @@ func (s *rpcServer) accept(sock transport.Socket) {
|
||||
delete(hdr, "Content-Type")
|
||||
|
||||
ctx := c.WithMetadata(context.Background(), hdr)
|
||||
s.rpc.ServeRequestWithContext(ctx, codec)
|
||||
// TODO: needs better error handling
|
||||
if err := s.rpc.ServeRequestWithContext(ctx, codec); err != nil {
|
||||
log.Errorf("Unexpected error servinc request, closing socket: %v", err)
|
||||
sock.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *rpcServer) Config() options {
|
||||
|
@ -157,6 +157,27 @@ func (h *httpTransportSocket) Send(m *Message) error {
|
||||
return rsp.Write(h.conn)
|
||||
}
|
||||
|
||||
func (h *httpTransportSocket) error(m *Message) error {
|
||||
b := bytes.NewBuffer(m.Body)
|
||||
defer b.Reset()
|
||||
rsp := &http.Response{
|
||||
Header: make(http.Header),
|
||||
Body: &buffer{b},
|
||||
Status: "500 Internal Server Error",
|
||||
StatusCode: 500,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
ContentLength: int64(len(m.Body)),
|
||||
}
|
||||
|
||||
for k, v := range m.Header {
|
||||
rsp.Header.Set(k, v)
|
||||
}
|
||||
|
||||
return rsp.Write(h.conn)
|
||||
}
|
||||
|
||||
func (h *httpTransportSocket) Close() error {
|
||||
return h.conn.Close()
|
||||
}
|
||||
@ -177,10 +198,19 @@ func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
||||
return
|
||||
}
|
||||
|
||||
fn(&httpTransportSocket{
|
||||
sock := &httpTransportSocket{
|
||||
conn: conn,
|
||||
r: r,
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: think of a better error response strategy
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
sock.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
fn(sock)
|
||||
}),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user