websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

Use tokio 0.1 (tokio reform updates) #199

Closed surdus closed 5 years ago

surdus commented 6 years ago

Related issue #165

vi commented 6 years ago

How does it compare to this repository?

kellerkindt commented 6 years ago

Thans @surdus , you made it available just as I needed it. I am currently using it in production and besides some sporadic disconnects (upstream write buffer fills up, which might be caused by another change of mine), its running fine.

surdus commented 6 years ago

How does it compare to this repository?

It is just tokio related updates with fix of all compile warnings (there were some related to deprecated methods). In repo you mentioned there is also updates for new hyper version as I see and looks it is still required some work to do (rust show warnings for some unused variables and deprecated methods). But in general looks like it also use new tokio

vi commented 6 years ago

So this pull request is probably for version 0.22.0 and enzious's version may be 0.23.0 (or later), if it would be ready.

vi commented 5 years ago

examples/async-client and websocat get race condition after this.

Server (websocat is based on current rust-websocket version):

$ websocat -b ws-l:127.0.0.1:2794 literal:12345
websocat: Unfortunately, serving multiple clients without --exit-on-eof (-E) or with -U option is prone to socket leak in this websocat version

rust-websocket without bug (2f9ab02e124f9b64352d40bd85b9392d36d92a66):

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

rust-websocket with this pull request merged in:

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
^C

$ strace -fo /dev/null target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
^C

$ target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

$ target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Close(None)
^C

$ target/debug/examples/async-client 
Connecting to ws://127.0.0.1:2794
Received Message: Binary([49, 50, 51, 52, 53])
Received Message: Close(None)
^C

The faster server and the slower client go, the more probability of missed message is. strace is just artificial slowdown.

surdus commented 5 years ago

Should works now. The problem was in codec update, non processed data in input buffer were lost. @kellerkindt issues that you mentioned may be related to this.