snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

Fix `poll_close` returning WouldBlock error kind #215

Closed CBenoit closed 2 years ago

CBenoit commented 2 years ago

Currently, poll_close is not checking for io::ErrorKind::WouldBlock on error, and instead it is bumbled up. For instance, calling the close helper from SinkExt:

ws.close().await.unwrap();

will cause a panic when WouldBlock occurs, instead of simply polling as expected.

This patch addresses this by returning Poll::Pending and then polling write_pending to drive the close operation to completion.