Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Respect timeout when cancellation token is provided#2207

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
JakubKopys wants to merge2 commits intodotnet:master
base:master
Choose a base branch
Loading
fromJakubKopys:fix-timeout

Conversation

@JakubKopys
Copy link

@JakubKopysJakubKopys commentedOct 14, 2025
edited
Loading

Context

Our code runs the MQTT Client in a Background Service.

Problem

Providing any CancellationToken to any of those methods -ConnectAsync,PingAsync,DisconnectAsync,SubscribeAsync, andUnsubscribeAsync disregards theTimeout option.

In Background Services, we always provide the cancellation token, so if we are not aware of this behaviour, those methods will never timeout, disregarding theWithTimeout orTimeout completely.
I do acknowledge this is partially mentioned in the Sample for timeouts, though, and it is recommended to use a linked token source.

I found it confusing, so I'm suggesting a change.

Solution

Instead of disregarding the Timeout, those operations should always consider it and link the cancellation sources.

I'm also aware this is a breaking change, as it'd cause Timeouts for existing code that depends on overwriting this with a linked token with an expiry.

Thank you for considering this contribution. I appreciate any feedback or suggestions for change. Alternatively, we could consider improving the sample and/or documentation.

@JakubKopys
Copy link
Author

@dotnet-policy-service agree

@JakubKopysJakubKopys changed the titleFix timeout when cancellation token is providedRespect timeout when cancellation token is providedOct 14, 2025
@chkr1011
Copy link
Collaborator

I understand the issue and the change look reasonable to me. The HTTP client in .NET behaves in the same way. The shorter timeout (or cancellation token) will cancel the operation. The only thing which I am thinking about is the breaking change you already mentioned.

When I am not wrong the breaking change will only affect users which cancel the passed cancellation token LATER than 100 seconds (default timeout in options, or custom value). Then the timeout will happen earlier as expected.

JakubKopys reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@JakubKopys@chkr1011

[8]ページ先頭

©2009-2025 Movatter.jp