11//! # FIXES:
2- //!
2+ //!
33//! The number is identical to the number in the GitHub issue tracker
44//!
55//! ## FIX ISSUE #4:
6- //!
6+ //!
77//! See:https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/4
88//! Some users reported false event notification causing the counter to increase
99//! due to the OS reporting a READ event after we already read the TcpStream to EOF.
1313//! The fix for this is to account for false wakeups which is an easy fix but requires
1414//! a few changes to the example. I've added an explicit comment: "FIX #4", the places
1515//! I made a change so it's easy to spot the differences to the example code in the book.
16- //!
16+ //!
1717//! ## TROUBLESHOOTING (KNOWN POTENTIAL ISSUE)
18- //!
18+ //!
1919//! ### EXAMPLE DOESN'T WORK AS EXPECTED - PROBLEM WITH DNS LOOKUP
2020//! If you first run this example on Linux under WSL and then immediately run it on
2121//! Windows, I've observed issues with the DNS lookup for "localhost" being so slow
2222//! that it defeats the purpose of the example. This issue could potentially also
2323//! happen under other scenarios than the one mentioned here and the fix will be
2424//! the same regardless.
25- //!
26- //! I don't consider this a bug with our code but a surprising behavior of the
27- //! WSL/Windows network stack. Anyway, if you encounter this, the fix is simple:
28- //!
25+ //!
26+ //! I don't consider this a bug with our code but a surprising behavior of the
27+ //! WSL/Windows network stack. Anyway, if you encounter this, the fix is simple:
28+ //!
2929//! Change `let addr = "localhost:8080";` to `let addr = "127.0.0.1:8080";`.
3030//!
3131
@@ -58,9 +58,7 @@ fn handle_events(events: &[Event], streams: &mut [TcpStream], handled: &mut Hash
5858 match streams[ index] . read ( & mut data) {
5959 Ok ( n) if n == 0 => {
6060 // FIX #4
61- // `insert` returns false if the value already existed in the set. We
62- // handle it here since we must be sure that the TcpStream is fully
63- // drained due to using edge triggered epoll.
61+ // `insert` returns false if the value already existed in the set.
6462 if !handled. insert ( index) {
6563 break ;
6664 }
@@ -117,7 +115,7 @@ fn main() -> Result<()> {
117115
118116 streams. push ( stream) ;
119117 }
120-
118+
121119 // FIX #4: store the handled IDs
122120 let mut handled_ids = HashSet :: new ( ) ;
123121
@@ -139,7 +137,7 @@ fn main() -> Result<()> {
139137 // Events collection
140138 let events: Vec < Event > = events. into_iter ( ) . map ( |e| e. clone ( ) ) . collect ( ) ;
141139 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142-
140+
143141 // ------------------------------------------------------⌄ FIX #4 (new signature)
144142 handled_events += handle_events ( & events, & mut streams, & mut handled_ids) ?;
145143 }
0 commit comments