-
Notifications
You must be signed in to change notification settings - Fork 86
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
Rewrite of the ntp-client #1327
Conversation
1bf4617
to
aba0a82
Compare
c75e318
to
ac8616d
Compare
ntp-client/src/Network/NTP/Client.hs
Outdated
Right _ -> traceWith tracer NtpTracePacketSent | ||
Left e -> do | ||
traceWith tracer $ NtpTracePacketSentError e | ||
ioError e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a onException
(or catch
if you only want to act on IOException
s). This will make transition to
MonadCatcheasier (it does not have the low level
System.IO` exception control flow functions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets leave that for a new PR
9c6423d
to
047a376
Compare
case (firstAddr AF_INET addr, firstAddr AF_INET6 addr) of | ||
(Nothing, Nothing) -> do | ||
traceWith tracer $ NtpTraceLookupServerFailed server | ||
ioError $ userError $ "lookup NTP server failed " ++ server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a custom exception rather than IOError
? Is there something specific to IOError
in the rest of the code base that relies on the fact that it is an IOException
? (e.g. an error handler that must catch it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to keep it simple the rest of the code only handles IOErrors explicitly and only IOErrors
and Async exceptions are expected to happen. All other exception are propagated.
All other exceptions are probably caused by bugs in the program.
It is not needed outside of `Query` module
GHC will be able to free memory taken by the tread earlier.
The test suite does not need rts, -threaded and -N options set.
* use explicit recursion * queryLoop - it must write the returned value by 'ntpQuery', otherwise a thread waiting for the update will not receive it. It is up the the application to decide what to do if 'NtpSyncUnavailable' is received. * improve documentation * return type is 'IO Void', which clearly indicates that this is an infinite loop.
When triggering a forceful update, check if the client is not already enaged in ntp protocols. If not trigger update, otherwise wait for completion of running ntp protocol instances.
This matches other test suites in 'ouroboros-network' package.
* mask async exception to guarantee that all threads are cancelled * no need to use `waitAnyCancel` inside `withAsync`` callback, `waitAny` is enough for threads started with `withAsync`.
bors r+ |
1327: Rewrite of the ntp-client r=coot a=MarcFontaine This PR started as a refactoring of the ntp-client but evolved into a re-implementation. (Therefore it does not make sense to review it as a diff) Co-authored-by: MarcFontaine <[email protected]> Co-authored-by: MarcFontaine <[email protected]> Co-authored-by: Marcin Szamotulski <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect the following:
- client runs OK for a while and then error
- retry in 5 10 20 40... seconds
- client runs OK for a while (expected this resets retry sequence) , and then error
- EXPECTED : retry in 5 10 20 40 ... seconds
- IMPLEMENTATION : retry in 80 160 320 .. seconds
@MarcFontaine could you elaborate. The client will use |
arg, there's a mistake, it should be:
not |
I created an issue we can discuss it there: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work:
getAddrInfo
needs a Just value for at least one of the HostName or ServiceName arguments
ntp-client/src/Network/NTP/Query.hs
Outdated
udpLocalAddresses :: IO [AddrInfo] | ||
-- Hints Host Service | ||
udpLocalAddresses = Socket.getAddrInfo (Just hints) Nothing (Just $ show port) | ||
udpLocalAddresses = Socket.getAddrInfo (Just hints) Nothing Nothing | ||
where | ||
hints = Socket.defaultHints | ||
{ addrFlags = [AI_PASSIVE] | ||
, addrSocketType = Datagram | ||
} | ||
port = Socket.defaultPort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work:
getAddrInfo
needs at least one Just argument.
Hi, |
Hi @mark-stopka It's worth to mention that this is not to substitute a proper ntp client run as a system service. |
Hi @coot, thanks for your feedback, Thanks for confirming, |
This PR started as a refactoring of the ntp-client but evolved into a re-implementation.
(Therefore it does not make sense to review it as a diff)