-
Notifications
You must be signed in to change notification settings - Fork 151
fix: ss2022 throughput, simple-obfs TLS state machine, MMDB path #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ use std::{ | |
| io, | ||
| net::SocketAddr, | ||
| pin::Pin, | ||
| sync::Mutex, | ||
| task::{Context, Poll}, | ||
| }; | ||
|
|
||
|
|
@@ -200,16 +201,16 @@ where | |
|
|
||
| /// Shadowsocks UDP I/O that ProxySocket required | ||
| pub(crate) struct ShadowsocksUdpIo { | ||
| w: tokio::sync::Mutex<SplitSink<AnyOutboundDatagram, UdpPacket>>, | ||
| r: tokio::sync::Mutex<(SplitStream<AnyOutboundDatagram>, BytesMut)>, | ||
| w: Mutex<SplitSink<AnyOutboundDatagram, UdpPacket>>, | ||
| r: Mutex<(SplitStream<AnyOutboundDatagram>, BytesMut)>, | ||
| } | ||
|
|
||
| impl ShadowsocksUdpIo { | ||
| pub fn new(inner: AnyOutboundDatagram) -> Self { | ||
| let (w, r) = inner.split(); | ||
| Self { | ||
| w: tokio::sync::Mutex::new(w), | ||
| r: tokio::sync::Mutex::new((r, BytesMut::new())), | ||
| w: Mutex::new(w), | ||
| r: Mutex::new((r, BytesMut::new())), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -225,7 +226,7 @@ impl DatagramSend for ShadowsocksUdpIo { | |
| buf: &[u8], | ||
| target: std::net::SocketAddr, | ||
| ) -> Poll<io::Result<usize>> { | ||
| let mut w = self.w.try_lock().expect("must acquire"); | ||
| let mut w = self.w.lock().unwrap(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid panicking on poisoned mutexes in UDP poll paths. Line 229, Line 247, and Line 259 use Suggested fix- let mut w = self.w.lock().unwrap();
+ let mut w = match self.w.lock() {
+ Ok(guard) => guard,
+ Err(_) => {
+ return Poll::Ready(Err(io::Error::other(
+ "shadowsocks udp writer lock poisoned",
+ )));
+ }
+ };
- let mut w = self.w.lock().unwrap();
+ let mut w = match self.w.lock() {
+ Ok(guard) => guard,
+ Err(_) => {
+ return Poll::Ready(Err(io::Error::other(
+ "shadowsocks udp writer lock poisoned",
+ )));
+ }
+ };
- let mut g = self.r.lock().unwrap();
+ let mut g = match self.r.lock() {
+ Ok(guard) => guard,
+ Err(_) => {
+ return Poll::Ready(Err(io::Error::other(
+ "shadowsocks udp reader lock poisoned",
+ )));
+ }
+ };Also applies to: 247-247, 259-259 🤖 Prompt for AI Agents |
||
| match w.start_send_unpin(UdpPacket { | ||
| data: buf.to_vec(), | ||
| src_addr: SocksAddr::any_ipv4(), | ||
|
|
@@ -243,7 +244,7 @@ impl DatagramSend for ShadowsocksUdpIo { | |
| } | ||
|
|
||
| fn poll_send_ready(&self, cx: &mut Context<'_>) -> Poll<io::Result<()>> { | ||
| let mut w = self.w.try_lock().expect("must acquire"); | ||
| let mut w = self.w.lock().unwrap(); | ||
| w.poll_ready_unpin(cx) | ||
| .map_err(|e| new_io_error(e.to_string())) | ||
| } | ||
|
|
@@ -255,7 +256,7 @@ impl DatagramReceive for ShadowsocksUdpIo { | |
| cx: &mut Context<'_>, | ||
| buf: &mut ReadBuf<'_>, | ||
| ) -> Poll<io::Result<()>> { | ||
| let mut g = self.r.try_lock().expect("must acquire"); | ||
| let mut g = self.r.lock().unwrap(); | ||
| let (r, remained) = &mut *g; | ||
|
|
||
|
Comment on lines
+259
to
261
|
||
| if !remained.is_empty() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says SS2022 max packet size is 0xFFFF (65535), but
DEFAULT_BUFFER_SIZEis set to64 * 1024(= 65536). Either adjust the constant to match the stated limit, or update the comment to explain why a 64 KiB buffer (one byte larger) is chosen (e.g., power-of-two sizing).