-
Notifications
You must be signed in to change notification settings - Fork 337
[dev] fix windows builds and timeouts #991
[dev] fix windows builds and timeouts #991
Conversation
4b55133
to
6aa8b0e
Compare
keepalive timer requires that we send a heartbeat message every so often and i'm gonna need |
7116a54
to
f794855
Compare
One thing I have a question about is my use of two separate tokio runtimes here. I'm wondering if there's a better pattern I should be using. |
I think this might fix #888 |
Yeah, two runtimes aren't ideal. I haven't dug into the code yet but https://docs.rs/tokio/0.2.9/tokio/task/fn.spawn.html is probably what you'd do |
So it turns out this builds on Windows but seems to not read incoming socket messages. I've opened this issue to see if the awesome folks over at |
@steveklabnik re: your comment about The following code starts and ends the process almost immediately, it seems to spawn the two tasks and then exit. let mut runtime = TokioRuntime::new().unwrap();
// listen for devtools messages
runtime.spawn(async move {
socket::listen(session_id).await
});
// handle incoming HTTP requests
runtime.spawn(async move {
serve(server_config, preview_id).await
})?; The following code seems to work at first, provides a "Listening" message, but fails to handle any incoming HTTP requests: let mut runtime = TokioRuntime::new().unwrap();
// listen for devtools messages
runtime.spawn(async move {
socket::listen(session_id).await
});
// handle incoming HTTP requests
runtime.block_on(async move {
serve(server_config, preview_id).await
})?; |
f794855
to
f298f18
Compare
f298f18
to
942b3c6
Compare
I seem to have cracked the code thanks to some help from the friendly Tokio discord server :) - only one runtime now |
71b9b41
to
3e9681f
Compare
[dev] uses PR #28 of chrome-devtools-rs
8808cdf
to
c9e03ec
Compare
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 looks good! I have a few questions/comments but in general, I approve :)
let devtools_listener = socket::listen(session_id); | ||
let server = serve(server_config, preview_id); | ||
|
||
let runners = futures::future::join(devtools_listener, 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.
🎊
src/commands/dev/mod.rs
Outdated
let runners = futures::future::join(devtools_listener, server); | ||
|
||
runtime.block_on(async { | ||
let (_, _) = runners.await; |
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.
any reason to not
let _ =
instead?
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.
also, are you sure that ignoring all failures is what you want here?
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.
That's a good point - I'm going to add some .unwrap()
calls to them. Not quite sure if there's a way for me to bubble up those failures through the async fn
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.
pub fn block_on<F: Future>(&mut self, future: F) -> F::Output
should return that Result
back out of block_on
, I think.
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.
very interesting - i think i got it
src/commands/dev/socket.rs
Outdated
Ok(()) | ||
} | ||
|
||
async fn keep_alive(tx: futures::channel::mpsc::UnboundedSender<Message>) { |
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.
might be worth giving this a return type of !
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.
Interesting! I'm not familiar with this syntax and can't seem to find an example of a function returning !
- would you mind elaborating?
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.
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.
(loop
has the type !
, but since !
coerces to any other type, it coerces to the return type of ()
here, which is why this code works the way it does)
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 is very cool
let duration = Duration::from_millis(1000 * KEEP_ALIVE_INTERVAL); | ||
let mut interval = time::interval(duration); | ||
|
||
let mut id = 2; |
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 am interested why this is 2. not because it's wrong, but it feels unusual! Might deserve a comment
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.
Fair point - the reason it's 2 is because we have already sent id = 1
earlier to enable the runtime. Eventually I plan on making the ID handling automatic and in the chrome-devtools-rs library.
thanks steve! |
This fixes the issues we were having with logs not working on windows!