mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-19 11:19:03 +02:00
rpc: re-architect connection teardown
Tear down occurs on each protocol level, stack-wise. Open RWC Open ML (with NewMessageLayer) Open RPC (with NewServer/ NewClient) Close RPC (with Close() from Client()) Close ML * in Server: after error / receive of Close request * in Client: after getting ACK for Close request from Server Close RWC To achieve this, a DataType for RPC control messages was added, which has a separate set of endpoints. Not exactly pretty, but works for now. The necessity of the RST frame remains to be determined. However, it is nice to have a way to signal the other side something went terribly wrong in the middle of an operation. Example: A frameBridingWriter fails to read the next chunk of a file it is supposed to send, it can just send an RST frame to signal this operation failed... Wouldn't trailers make sense then?
This commit is contained in:
@@ -84,9 +84,12 @@ func (s *Server) recvRequest() (h *Header, err error) {
|
||||
}
|
||||
|
||||
var doneServeNext error = errors.New("this should not cause a HangUp() in the server")
|
||||
var doneStopServing error = errors.New("this should cause the server to close the connection")
|
||||
|
||||
var ProtocolError error = errors.New("protocol error, server should hang up")
|
||||
|
||||
const ControlEndpointClose string = "Close"
|
||||
|
||||
// Serve the connection until failure or the client hangs up
|
||||
func (s *Server) Serve() (err error) {
|
||||
for {
|
||||
@@ -96,16 +99,31 @@ func (s *Server) Serve() (err error) {
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err == doneServeNext {
|
||||
s.logger.Printf("subroutine returned pseudo-error indicating early-exit")
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
|
||||
s.logger.Printf("hanging up after ServeRequest returned error: %s", err)
|
||||
s.ml.HangUp()
|
||||
return err
|
||||
if err == doneStopServing {
|
||||
s.logger.Printf("subroutine returned pseudo-error indicating close request")
|
||||
err = nil
|
||||
break
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.logger.Printf("an error occurred that could not be handled on PRC protocol level: %+v", err)
|
||||
}
|
||||
|
||||
s.logger.Printf("cloing MessageLayer")
|
||||
if mlErr := s.ml.Close(); mlErr != nil {
|
||||
s.logger.Printf("error closing MessageLayer: %+v", mlErr)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Serve a single request
|
||||
@@ -129,6 +147,22 @@ func (s *Server) ServeRequest() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if h.DataType == DataTypeControl {
|
||||
switch h.Endpoint {
|
||||
case ControlEndpointClose:
|
||||
ack := Header{Error: StatusOK, DataType: DataTypeControl}
|
||||
err = s.writeResponse(&ack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return doneStopServing
|
||||
default:
|
||||
r := NewErrorHeader(StatusRequestError, "unregistered control endpoint %s", h.Endpoint)
|
||||
return s.writeResponse(r)
|
||||
}
|
||||
panic("implementation error")
|
||||
}
|
||||
|
||||
ep, ok := s.endpoints[h.Endpoint]
|
||||
if !ok {
|
||||
r := NewErrorHeader(StatusRequestError, "unregistered endpoint %s", h.Endpoint)
|
||||
|
Reference in New Issue
Block a user