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

we might have a HostEntry in the dns cache already #11126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

caolanm
Copy link
Contributor

@caolanm caolanm commented Feb 10, 2025

Change-Id: I2a08bd77f837ba3b8a2a57e90e79ce5bb86305e8

  • Resolves: #
  • Target version: master

Summary

TODO

  • ...

Checklist

  • I have run make prettier-write and formatted the code.
  • All commits have Change-Id
  • I have run tests with make check
  • I have issued make run and manually verified that everything looks okay
  • Documentation (manuals or wiki) has been updated or is not required

@caolanm caolanm force-pushed the private/caolan/use_dns_cache_more branch 7 times, most recently from 4b9822a to ff75c93 Compare February 13, 2025 16:40
@caolanm caolanm requested a review from Ashod February 13, 2025 20:55
Copy link
Contributor

@Ashod Ashod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @caolanm. I like the direction, but have concerns with switching the callback. I think we should work towards a better design that handles this case seamlessly.

}

poller.insertNewSocket(socket);
origOnConnectFail(rSession);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that origOnConnectFail is valid. There is no guarantee that it is.

{
// Intercept onConnectFail to detect connection failure, call the original (if any),
// and finish the response to end the poller loop.
setConnectFailHandler([this, origOnConnectFail](const std::shared_ptr<http::Session>& rSession) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have to do this, something is likely wrong with the design. (Also see below.)

If we need this to call _response->finish();, then the question is: why isn't it called when the connection fails anyway?

I think we should call onDisconnect() (or its equivalent) from callOnConnectFail().

The original design is to always call the 'onFinished' handler. We promise this for the setFinishedHandler():

    /// Set a callback to handle onFinished events from this session.
    /// onFinished is triggered whenever a request has finished,
    /// regardless of the reason (error, timeout, completion).
    void setFinishedHandler(FinishedCallback onFinished) { _onFinished = std::move(onFinished); }

So it's a good idea to do so when we fail to connect as well. We can extend the Response::State enum to include ConnectionError (we can rename the current Error to ProtocolError), and always invoke the same onDisconnect() and onFinished, to let the client do whatever cleanup and/or continuation.

(I'm not sure we ever needed a 'connectFailHandler', as such, rather than AsyncConnectResult + onFinished. Perhaps what's missing is the new State above?)


const auto remaining =
std::chrono::duration_cast<std::chrono::microseconds>(deadline - now);
poller.poll(remaining);
}

setConnectFailHandler(origOnConnectFail);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exception-safe. Yet another problem with the need to switch handlers, which we should avoid by having a more homogeneous design.

@caolanm
Copy link
Contributor Author

caolanm commented Feb 19, 2025

My assumption here with "routing syncRequestImpl connect through asyncDNS" was that the remaining "sync" dns use in wsd/Storage.cpp StorageBase::validate might be amenable to being split up into something where the result in an async callback would be usable so all the remaining sync DNS uses could be dropped. That looks plausible for the uses in wsd/RequestVettingStation.cpp and wsd/wopi/WopiProxy.cpp, but the StorageBase::create use of validate looks much more uncertain to achieve successfully.

Trying an alternative approach of passing a HostEntry to "validate" and bubbling that down from the initial places the uri can come from becomes unwieldy pretty fast and terminates in a bunch of places where have the same issue.

So lets try another alternative.

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: I2a08bd77f837ba3b8a2a57e90e79ce5bb86305e8
@caolanm caolanm force-pushed the private/caolan/use_dns_cache_more branch 2 times, most recently from 9bc06b5 to 349e6ac Compare February 20, 2025 08:19
so can cache regardless of port, and apply the port when needed
to a copy of the result

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: I8142b16dec85a3cca3d0c1acc1467accd0aab671
so we have a single cache of DNS results.

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: I72f39ddaa1badb245f7e04c6f9c6b4c8d20f67fc
@caolanm caolanm force-pushed the private/caolan/use_dns_cache_more branch from 349e6ac to 0f15681 Compare February 20, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Review
Development

Successfully merging this pull request may close these issues.

2 participants