fix:close transport on connection failure#1862
fix:close transport on connection failure#1862sid293 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…during client connect
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
felixweinberger
left a comment
There was a problem hiding this comment.
Hi @sid293 thanks for this - did you come across this in something you were working on or is this purely speculative based on reading the source?
Some context for how you ran into this issue would be great.
| headers: { | ||
| 'user-agent': 'MyApp/1.0' | ||
| } | ||
| }); |
There was a problem hiding this comment.
If we need this type assertion to make this work, that's a sign the solution isn't quite there yet.
Fixes a resource leak on connection failure and resolves TypeScript error in
packages/client/test/client/auth.test.ts.Motivation and Context
client.ts: Movedsuper.connect()inside thetryblock so thecatchblock can properly close the transport if initialization fails.auth.test.ts: Addedas unknown as RequestInitto resolve a type mismatch on the optionalcacheproperty.How Has This Been Tested?
Added a new integration test to verify that the transport is closed even when startup fails.
All tests were verified passing using the workspace-wide command:
pnpm test:allBreaking Changes
none
Types of changes
Checklist
Additional context