mcp: don't persist failed streamable sessions (#605)
If a stateful streamable session fails to initialize, it is unusable. Avoid allocating resources by closing the session immediately. Also: - Fix a bug where InitializeParams is not guarded with its mutex. - Fix a resource leak where sessions are persisted with session id "", even though they are unaddressable. - Add a relevant benchmark, and update tests. Fixes #578
This commit is contained in:
parent
ae6bda692b
commit
d256a9c109
1 changed files with 113 additions and 7 deletions
|
|
@ -1145,7 +1145,13 @@ func (ss *ServerSession) handle(ctx context.Context, req *jsonrpc.Request) (any,
|
|||
return handleReceive(ctx, ss, req)
|
||||
}
|
||||
|
||||
func (ss *ServerSession) InitializeParams() *InitializeParams { return ss.state.InitializeParams }
|
||||
// InitializeParams returns the InitializeParams provided during the client's
|
||||
// initial connection.
|
||||
func (ss *ServerSession) InitializeParams() *InitializeParams {
|
||||
ss.mu.Lock()
|
||||
defer ss.mu.Unlock()
|
||||
return ss.state.InitializeParams
|
||||
}
|
||||
|
||||
func (ss *ServerSession) initialize(ctx context.Context, params *InitializeParams) (*InitializeResult, error) {
|
||||
if params == nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue