Skip to content

Commit

Permalink
fix: Regression where on_close is called more than once, close housle…
Browse files Browse the repository at this point in the history
  • Loading branch information
housleyjk committed Jun 8, 2017
1 parent 080ba04 commit 5515b1c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target
todo.txt
/tests/reports
.project
.cache

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<a name="v0.7.3"></a>
### v0.7.3 (2017-06-07)


#### Bug Fixes

* Issue with `on_close` called twice


<a name="v0.7.2"></a>
### v0.7.2 (2017-06-04)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
name = "ws"
readme = "README.md"
repository = "https://github.com/housleyjk/ws-rs"
version = "0.7.2"
version = "0.7.1"

[dependencies]
httparse = "1.0"
Expand Down
8 changes: 6 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,12 @@ impl<H> Connection<H>
while let Some(len) = try!(self.buffer_in()) {
try!(self.read_frames());
if len == 0 {
self.events.remove(Ready::readable());
break;
if self.events.is_writable() {
self.events.remove(Ready::readable());
} else {
self.disconnect()
}
break
}
}
Ok(())
Expand Down
9 changes: 3 additions & 6 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use connection::Connection;
use factory::Factory;
use util::Slab;
use super::Settings;
use protocol::CloseCode;
use handler::Handler as HandlerT;

const QUEUE: Token = Token(usize::MAX - 3);
const TIMER: Token = Token(usize::MAX - 4);
Expand Down Expand Up @@ -470,8 +468,7 @@ impl<F> Handler<F>
} else {
trace!("WebSocket connection to token={:?} disconnected.", token);
}
let mut handler = self.connections.remove(token).unwrap().consume();
handler.on_close(CloseCode::Abnormal, "");
let handler = self.connections.remove(token).unwrap().consume();
self.factory.connection_lost(handler);
} else {
self.schedule(poll, &self.connections[token]).or_else(|err| {
Expand Down Expand Up @@ -579,9 +576,9 @@ impl<F> Handler<F>
self.connections[token].error(err)
}
}

let conn_events = self.connections[token].events();

if (events & conn_events).is_writable() {
if let Err(err) = self.connections[token].write() {
trace!("Encountered error while writing: {}", err);
Expand Down

0 comments on commit 5515b1c

Please sign in to comment.