Comments (9)
I agree with you that having to call drop
explicitly is pretty unfortunate. The reason it is currently needed is to avoid swallowing any errors. I could have the implementation of Drop
resolve the fin
future internally, which would in turn mean you can just let Client
fall out of scope as normal, but this would also mean that if any errors occur when tearing down the connection, that error would either be hidden from the user, or cause a panic (if drop
calls unwrap
).
For what it's worth, the reason that Client
has to be explicitly dropped is that it internally contains a reference-counted Inner
(This is what allows Client
to be Clone
). Only when the last Client
is dropped will Inner
's destructor be called (which calls shutdown
). If shutdown
isn't called, then a) the WebDriver session isn't terminated, and b) fin
would never resolve.
from fantoccini.
Pushed a proposed change in bd4c9d1 — how does that look to you?
See in particular:
Lines 362 to 369 in bd4c9d1
and
Lines 757 to 771 in bd4c9d1
As well as the updated examples in the README.
from fantoccini.
This is definitely a usage improvement!
Is there machinery that prevents the fin
future from being driven to completion (thus ending the session) before the actual work is completed?
from fantoccini.
This is definitely a usage improvement!
Great!
Is there machinery that prevents the
fin
future from being driven to completion (thus ending the session) before the actual work is completed?
Hmm, I'm not entirely sure what you mean here. I think what you're asking is why fantoccini can't just internally run the fin
future to completion, and thus do the cleanup for the user? If so, the answer is that the library only has a Handle
to the Tokio Core
used to drive the HTTP connection to the WebDriver server. It can schedule work for that core using the handle, but it can't actually execute that work. Therefore, it becomes up to the caller (who has the Core
) to use core.run()
to complete the request. The library also cannot just create a new Core
for doing cleanup, because the hyper::Client
is already tied to the user's original Handle
:
Lines 382 to 384 in 5998924
from fantoccini.
Sorry I was not very clear.
I meant "are we sure that the cleanup future won't execute until after all of the actual work* is done?"
from fantoccini.
Ah, I see. Technically, no. I don't think tokio/hyper gives guarantees about the order in which futures/requests are resolved. Given that they're all asynchronous, I suppose theoretically some existing WebDriver request could be lying around somewhere, not yet written to the wire, and then the shutdown command could be spawned on the core and race ahead of the existing command. But this sounds pretty unlikely to occur in practice to me. it's also not clear that we have a way to guard against this internally in the library, since we have no control over the execution of the futures that we return.
from fantoccini.
Publishing this now as 0.8.0, but open to further suggestions for how to improve the API :)
from fantoccini.
@jonhoo Still didn't get is there a way to make Client to close when exiting its scope?
from fantoccini.
No, sadly there is no such way since when a Client
is dropped it is not able to execute any asynchronous code. We could perhaps check if there was still an active runtime, and if so, spawn the destructor, but that's itself pretty error-prone, and could result in some weird unexpected behavior. What we really want are Asynchronous Destructors, but those don't seem like they're going to be here any time soon.
from fantoccini.
Related Issues (20)
- Cannot set `pageLoadOptions` in capabilities HOT 2
- WebAuthn support HOT 1
- BrowserStack requires `charset=utf-8` in `Content-Type` header on Selenium >= 4 HOT 1
- 👋 From the Selenium project! HOT 1
- Cannot access error variant information from webdriver::ErrorStatus enum HOT 1
- `Session::with_capabilities_and_connector` hides the WebDriver response HOT 1
- What's happening here? (fantoccini breaks String + &String) HOT 10
- Error when connecting to browserstack: Session not started or terminated HOT 1
- Test whether text is visible? HOT 3
- excute() doesnt execute some scripts correctly HOT 3
- SessionNotCreated error on second run with fantoccini and geckodriver HOT 1
- How to specify options for webdriver? HOT 1
- An error occurs in the IE mode of the Edge browser. HOT 2
- Testing of client&server-side Rust interaction HOT 1
- returning Prototype.Array shows in console.log but nothing from println. HOT 1
- Can you automate the geckodriver session initialization? HOT 2
- Please add Network Request Interception HOT 1
- Get console log messages HOT 1
- webdriver might be part of public API HOT 1
- WheelActions needed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fantoccini.