-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC WS refactor #811
RPC WS refactor #811
Conversation
d917f82
to
3149675
Compare
- Use channel/goroutine for sending messages - Rework connect/reconnect logic - Remove WS specific logic from common RPC layer Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
logrus.Infof("RPC: no connection to %v, reconnect in %v at %v", address, time.Until(*reconn), reconn) | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you handle deleting items from reconnMap?
var ( | ||
connMap = make(map[string]*RPCConnWS) | ||
reconnMap = make(map[string]*time.Time) | ||
connMapLock = sync.Mutex{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something I was wondering about, do we need another lock for the reconnMap?
@@ -18,7 +18,7 @@ type RPCConnHTTP struct { | |||
} | |||
|
|||
// NewRPCConnHTTP returns a new http connection | |||
func NewRPCConnHTTP(r *RPC, address string) *RPCConnHTTP { | |||
func NewRPCConnHTTP(r *RPC, address string) RPCConn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not keep using RPCConnHTTP?
Since this PR is changing a very infrastructural module and is not addressing a specific bug, I want to avoid unintended consequences. |
RPC WS refactor
Description
Abstract
RPCConnWS implements RPCConn interface used by the RPC layer in terms of nhooyr.io/websocket transport. RPC messages are dispatched according to address URL protocol in GetConnection().
States
RPCConnWS is a WebSocket connection that is shared and multiplexed
for all concurrent requests to the same address. An RPCConnWS instance is constructed in a connected state and ready for executing RPC Calls.
nil
is returned if connection refused or within reconnect delay. RPCConnWS detects peer disconnect on send and receives paths enhanced by heartbeat Ping goroutine and closes gracefully.Connection, reconnection map
NewRPCConnWS uses connection and reconnection tables mapped by the connection's address URL. The state shared by the construction and closing logic is guarded by the mutex, unlocking is insured by deferring unlock.
IO
Threads
An open connection is served by three goroutines two of those pump messages between the WebSocket and Call and Reply channels, while one is used for WS control ping-pong to improve reaction time to peer disconnect.
Shared state
IO "in-flight" state is tracked using RPCConnWS PendingRequests mapped by the request's ID. Request ID counter increment, the state shared by the IO read/send/close threads is guarded by the connection mutex, unlocking is insured by deferring unlock.