Skip to content

Commit ffb7714

Browse files
Merge pull request #206 from lrbalt/master
Do not panic on connection reset
2 parents 03de235 + ab70e6e commit ffb7714

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

audio/src/decrypt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::Add;
88
use core::audio_key::AudioKey;
99

1010
const AUDIO_AESIV: &'static [u8] = &[
11-
0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93
11+
0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93,
1212
];
1313

1414
pub struct AudioDecrypt<T: io::Read> {

audio/src/fetch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bit_set::BitSet;
22
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
3-
use futures::Stream;
43
use futures::sync::{mpsc, oneshot};
4+
use futures::Stream;
55
use futures::{Async, Future, Poll};
66
use std::cmp::min;
77
use std::fs;

audio/src/lewton_decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ where
2525
}
2626

2727
pub fn next_packet(&mut self) -> Result<Option<VorbisPacket>, VorbisError> {
28+
use self::lewton::audio::AudioReadError::AudioIsHeader;
2829
use self::lewton::OggReadError::NoCapturePatternFound;
2930
use self::lewton::VorbisError::BadAudio;
3031
use self::lewton::VorbisError::OggError;
31-
use self::lewton::audio::AudioReadError::AudioIsHeader;
3232
loop {
3333
match self.0.read_dec_packet_itl() {
3434
Ok(Some(packet)) => return Ok(Some(VorbisPacket(packet))),

connect/src/spirc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ impl Future for SpircTask {
301301
loop {
302302
let mut progress = false;
303303

304+
if self.session.is_invalid() {
305+
return Ok(Async::Ready(()));
306+
}
307+
304308
if !self.shutdown {
305309
match self.subscription.poll().unwrap() {
306310
Async::Ready(Some(frame)) => {

core/src/session.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use mercury::MercuryManager;
2020
struct SessionData {
2121
country: String,
2222
canonical_username: String,
23+
invalid: bool,
2324
}
2425

2526
struct SessionInternal {
@@ -77,7 +78,9 @@ impl Session {
7778
reusable_credentials.username.clone(),
7879
);
7980

80-
handle.spawn(task.map_err(|e| panic!(e)));
81+
handle.spawn(task.map_err(|e| {
82+
error!("{:?}", e);
83+
}));
8184

8285
session
8386
});
@@ -104,6 +107,7 @@ impl Session {
104107
data: RwLock::new(SessionData {
105108
country: String::new(),
106109
canonical_username: username,
110+
invalid: false,
107111
}),
108112

109113
tx_connection: sender_tx,
@@ -212,6 +216,15 @@ impl Session {
212216
pub fn session_id(&self) -> usize {
213217
self.0.session_id
214218
}
219+
220+
pub fn shutdown(&self) {
221+
debug!("Invalidating session[{}]", self.0.session_id);
222+
self.0.data.write().unwrap().invalid = true;
223+
}
224+
225+
pub fn is_invalid(&self) -> bool {
226+
self.0.data.read().unwrap().invalid
227+
}
215228
}
216229

217230
#[derive(Clone)]
@@ -240,6 +253,7 @@ where
240253
impl<S> Future for DispatchTask<S>
241254
where
242255
S: Stream<Item = (u8, Bytes)>,
256+
<S as Stream>::Error: ::std::fmt::Debug,
243257
{
244258
type Item = ();
245259
type Error = S::Error;
@@ -251,7 +265,15 @@ where
251265
};
252266

253267
loop {
254-
let (cmd, data) = try_ready!(self.0.poll()).expect("connection closed");
268+
let (cmd, data) = match self.0.poll() {
269+
Ok(Async::Ready(t)) => t,
270+
Ok(Async::NotReady) => return Ok(Async::NotReady),
271+
Err(e) => {
272+
session.shutdown();
273+
return Err(From::from(e));
274+
}
275+
}.expect("connection closed");
276+
255277
session.dispatch(cmd, data);
256278
}
257279
}

playback/src/mixer/softmixer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::sync::Arc;
21
use std::sync::atomic::{AtomicUsize, Ordering};
2+
use std::sync::Arc;
33

44
use super::AudioFilter;
55
use super::Mixer;

playback/src/player.rs

+4
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ impl PlayerInternal {
341341
self.handle_packet(packet, current_normalisation_factor);
342342
}
343343
}
344+
345+
if self.session.is_invalid() {
346+
return;
347+
}
344348
}
345349
}
346350

0 commit comments

Comments
 (0)