Plumb connection limit to proxy and output it (#384)
This commit is contained in:
1 parent
7db0e2a5ed
commit
f7e48ec836
9 files changed
+149
-59
No files matched your search
@@ -110,7 +110,8 @@ func (w *Worker) handleProxy() http.HandlerFunc {
|
||||
}
|
||||
|
||||
var ci *connInfo
|
||||
ci, err = w.authorizeConnection(r.Context(), sessionId)
|
||||
var connsLeft int32
|
||||
ci, connsLeft, err = w.authorizeConnection(r.Context(), sessionId)
|
||||
if err != nil {
|
||||
w.logger.Error("unable to authorize conneciton", "error", err)
|
||||
conn.Close(websocket.StatusInternalError, "unable to authorize connection")
|
||||
@@ -127,7 +128,8 @@ func (w *Worker) handleProxy() http.HandlerFunc {
|
||||
w.logger.Trace("authorized connection", "connection_id", ci.id)
|
||||
|
||||
handshakeResult := &proxy.HandshakeResult{
|
||||
Expiration: expiration,
|
||||
Expiration: expiration,
|
||||
ConnectionsLeft: connsLeft,
|
||||
}
|
||||
if err := wspb.Write(connCtx, conn, handshakeResult); err != nil {
|
||||
w.logger.Error("error sending handshake result to client", "error", err)
|
||||
|
||||
@@ -148,28 +148,28 @@ func (w *Worker) activateSession(ctx context.Context, sessionId, tofuToken strin
|
||||
return resp.GetStatus(), nil
|
||||
}
|
||||
|
||||
func (w *Worker) authorizeConnection(ctx context.Context, sessionId string) (*connInfo, error) {
|
||||
func (w *Worker) authorizeConnection(ctx context.Context, sessionId string) (*connInfo, int32, error) {
|
||||
rawConn := w.controllerSessionConn.Load()
|
||||
if rawConn == nil {
|
||||
return nil, errors.New("could not get a controller client")
|
||||
return nil, 0, errors.New("could not get a controller client")
|
||||
}
|
||||
conn, ok := rawConn.(pbs.SessionServiceClient)
|
||||
if !ok {
|
||||
return nil, errors.New("could not cast atomic controller client to the real thing")
|
||||
return nil, 0, errors.New("could not cast atomic controller client to the real thing")
|
||||
}
|
||||
if conn == nil {
|
||||
return nil, errors.New("controller client is nil")
|
||||
return nil, 0, errors.New("controller client is nil")
|
||||
}
|
||||
|
||||
resp, err := conn.AuthorizeConnection(ctx, &pbs.AuthorizeConnectionRequest{
|
||||
SessionId: sessionId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error authorizing connection: %w", err)
|
||||
return nil, 0, fmt.Errorf("error authorizing connection: %w", err)
|
||||
}
|
||||
|
||||
return &connInfo{
|
||||
id: resp.ConnectionId,
|
||||
status: resp.GetStatus(),
|
||||
}, nil
|
||||
}, resp.GetConnectionsLeft(), nil
|
||||
}
|
||||
Reference in new issue
Block a user