Building a Rust Multithreaded Web Server (20)

preview_player
Показать описание
This session is our final chapter in the Rust Lang Book series!

Alex, Ciara and Chris talk through building a multithreaded web server using the raw functionality provided by Rust. We start with building a single-threaded server, make that server multi-threaded, and finally handle graceful cleanup and shutdown.

In the process we found some interesting behavior where our shutdown didn't complete as expected. So far we have only managed to reproduce on windows - if anyone has any thoughts on what the problem might be or how to fix it let us know!

Chapter 20: Final Project: Building a Multithreaded Web Server

Рекомендации по теме
Комментарии
Автор

Another suspect is commit which (on May 6, 2022) changed calls to TcpStream.write() to be write_all(), dealing with issues #1990, #2237. The description of the issues doesn’t indicate a bug, but perhaps the worker thread was stuck inside its “job()” i.e. inside handle_connection() after having written a (partial) response back to the browser, perhaps stuck in the ‘drop()’ implementation of TcpStream, waiting for the connection to close (I would assume the call to flush() would handle such stuff).
In your discussion you assume that what “released the lock” was an extra query from the browser - but perhaps it was just the cancellation of an existing one. This can be checked if instead of hitting F5 on the browser once the server seems stuck, just try to close the browser tab and see if it has an effect.
Cheers

Roibarkan
Автор

It seems that commit to rust-lang/book (May 12, 2022) changes the signaling mechanism from a Terminate message to a “more idiomatic” closing of the sender. The reported issue (#119) for this change doesn’t indicate a functionality problem, just that it would be better to teach people about dropping the sender of a mpsc as an idiom for shutdown.

Roibarkan