-
Notifications
You must be signed in to change notification settings - Fork 115
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
cannot recursively call into Core #319
Comments
This behavior was, in theory, never permitted. It was just never enforced. Could you explain more how you were using it? It would probably be best to figure out a way around it. |
As I said, it's a test, this one: https://github.com/vorner/corona/blob/master/test/recursive_core.rs. I put some core-related things into TLS, and I wanted to check I don't mix it up if there are multiple and take turns or something. I can probably just throw the test out, when it comes to that. I'm just waiting for the waters to calm down before I port the whole library onto the new tokio anyway, so it won't be relevant any more. My point was more about this might be an oversight or something like that. Anyway, if it acts like it should, it probably should be documented in the |
If I’m understanding this properly, doesn’t this meant that two independent libraries can’t create Cores separately in the case where one might depend on the next? Especially in the case of wrappers that might be attempting to create synchronous interfaces? Do we need to enforce that a Core is the only Core on any particular thread? |
My understanding is you can run one core, let it terminate, then run another. But if you create one core, spawn a future into it and inside that future create another core and run it, it'll panic because you most likely don't want that. The inner core would be blocking inside the outer one and the outer one would not be able to execute futures at the time. And in my understanding libraries should never create their own cores, but be provided with a handle (or tokio::runtime) by the application and spawn whatever they need onto that. |
@bluejekyll as @vorner stated above, you can create an arbitrary number of cores per thread. What you cannot do is block on a core (call run) from within a future as that would be pretty disasterous to the Async runtime characteristics. |
Is this safe? https://github.com/bluejekyll/trust-dns/blob/master/resolver/src/resolver.rs#L126 Also, I know it’s not efficient, and I’ve planned to change it, but I’m concerned it’s not safe at the moment. |
This removes an invalid use of futures: previously, the client would create its own instance of a tokio_core reactor core and synchronously block on this core while waiting for a response. With recent releases of futures, this results in the error "cannot recursively call into `Core`". This is discussed at tokio-rs/tokio-core#319 and was apparently never correct behavior. To solve the problem and continue to use futures, it would be necessary to allow the client to spawn new futures on an existing executor. However, because the futures API is in flux right now and the current behavior was simply to block synchronously on the response anyway, I simply reverted the use of hyper to an older, pre-futures version and kept the public API of xml-rpc unchanged. In the future (e.g. once the futures ecosystem has settled down), it would be good to remove the blocking wait, but for now this works for me.
I'm hitting this issue with two libraries that manage their own cores ( A few questions:
|
Ah yes, that is unfortunate. However, nesting calls to I would rather dig in and figure out why you need to nest calls to |
Actually, there are several cases where it will grind the thread to a halt. I've seen this reported before in hyper, where people have a |
I agree in my case it'd probably make sense to make the trait I was working with futures-aware, but that will take some time to refactor. I have basically just spawned a separate thread to work around it for the time being. I still was initially horrified over the panic, as I was not expecting it to happen at all! It would be nice if there was a Result returned instead, so I can deal with this at compile time, not when it popped up during runtime. I understand that'd probably break the signature of At the bare minimum, maybe some documentation along the lines of: Calling this method when inside an existing future's execution (i.e, recursively) on the same thread will cause a panic, as it would otherwise cause a deadlock |
Yeah, we cannot break the signature of Would you mind submitting a PR that includes the snippet under the "panics" section of the docs? |
Ok, I will submit a PR |
Hello
It seems that by using
tokio-executor
under the hood, the behaviour changed in backwards-incompatible way. If inside one future I create a new core and try to run something in it, it panics withcannot recursively call into Core
(https://github.com/tokio-rs/tokio-core/blob/master/src/reactor/mod.rs#L242).I know this is an edge case and that I'd try to avoid it in a real application (I use it in some tests, checking some edge cases of my own) and that the reason for it is to actually disallow this degenerate case, but it was allowed before, so I don't know if it's OK to forbid it now.
The text was updated successfully, but these errors were encountered: