Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout not working when using Async methods #13

Open
tipa opened this issue Jan 30, 2023 · 2 comments
Open

Timeout not working when using Async methods #13

tipa opened this issue Jan 30, 2023 · 2 comments

Comments

@tipa
Copy link

tipa commented Jan 30, 2023

Tested with GuerillaNtp v3.0.0 & .NET for macOS

Code:

var ntpClient = new NtpClient(NtpClient.DefaultEndpoint, TimeSpan.FromSeconds(0.001));
var clock = await ntpClient.QueryAsync().ConfigureAwait(false);

Expected behaviour:
OperationCanceledException or similar Exception

Actual behaviour:
Timeout is ignored. QueryAsync can be awaited for much longer, potentially indefinitely, without any exception being thrown.

The docs only mention that the synchronous Receive method might use this timeout.
https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receivetimeout?view=net-7.0

There's also another Timeout, for synchronous Send methods, currently it doesn't seem to be used anywhere in this library: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.sendtimeout?view=net-7.0

If this is expected behaviour, it should be explained in detail in the docs. It currently only says "Query timeout" which is pretty vague. I expected this to be a timeout for any method (async or synchronous) that I call on the NtpClient method (and not on the underlying socket). I think the timeout should be implemented differently, perhaps using a CancellationTokenSource and CancelAfter

@olfek
Copy link

olfek commented Oct 5, 2024

I'm doing this as a workaround which seems to work.

var client = new NtpClient(...);
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(1));
await client.QueryAsync(cts.Token);

@olfek
Copy link

olfek commented Oct 5, 2024

@robertvazan 🛎️🛎️🛎️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants