Recently I encountered an issue while trying to update an application to tokio 1.0. The issue is solved (I'll describe it in a moment in case it helps anyone else), but I have a curious question that resulted from experiencing and addressing the issue.
I'm sure experienced tokio devs can guess what happened: I updated the tokio dependency and related libs, made all the code changes that were necessary for build + tests to run, and all looked good ... but when I ran the app I got the following runtime panic:
thread 'main' panicked at 'not currently running on the Tokio runtime.', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.24/src/runtime/handle.rs:118:28
Once I'd got past the initial surprise I noticed the
tokio-0.2.24 version in there, and quickly realized that one small part of the code was using a library that was still pulling in tokio 0.2, in a way that could not readily be addressed (there was not a usable update of that library with tokio 1.0 support).
A bit of searching around found me the
tokio_compat_02 crate, and I was easily able to fix up the bit of code in question to integrate with the tokio 1.0 runtime. This was quite a relief, because until I discovered that I thought I had come across a major (and nasty) hole in the "automatically bring in multiple versions of dependencies if needed" behaviour that cargo supports.
However, that led to me wondering: why was this error not detectable at compile time?
I wonder if anyone with greater experience in the tokio framework could offer some thoughts on that: I'm anticipating that there might be some interesting things to learn from the explanation.
Thanks and best wishes,