Skip to content

the context.RequestAborted not reliable in HandleSseRequestAsync #1606

@truelife2

Description

@truelife2

Describe the bug
the Request object will disposed when the connection was not normal disconnected, and the context.RequestAborted has two situations.
1.the context RequestAboated will disposed ,but will not raise registe event notify it was cancelled;because it just disposed.
2.the request will disposed, but the ReuqestAborted not changed,it stay not cancelled state.

the HandleSseRequestAsync method use RequestAborted to created a token source, when the request was disposed this token source will always be not cancelled, because it will not raise Registe event or RequestAborted will always not be cancelled, then the await RunSessionAsync will forever wait for next request.

using CancellationTokenSource sseCts = CancellationTokenSource.CreateLinkedTokenSource(context.RequestAborted, <hostApplicationLifetime>P.ApplicationStopping);

To Reproduce
Steps to reproduce the behavior:
just use mcp inspector ,click the "connect" button ,then quickly use ctrl+F4 to close the webpage,
or use RunSessionHandler to debug then wait it timeout.

Expected behavior
the cancellationToken must to become canceled, even the request was not normal disconnected.

Logs

Additional context
i have not better idea for this, maybe can use context.Reponse.OnCompleted(()=>sseCts.Cancel()) to fix the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions