Skip to content

Commit 3124fa7

Browse files
committed
helper-rust: extend forceful disconnect detection to ECONNRESET and EPIPE
Rename is_incomplete_stream_error to is_forceful_disconnect_error and extend it to also treat ECONNRESET and EPIPE as forceful disconnects. On Linux, ECONNRESET is delivered to the peer when a Unix socket is closed while its receive buffer is non-empty (unix_release_sock), indicating the client crashed or was killed after we sent our response — a connectivity issue, not a protocol error. Also remove redundant `git config --global --add safe.directory '*'` calls from integration Docker build tasks.
1 parent cc6401a commit 3124fa7

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

appsec/helper-rust/src/client.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ async fn recv_command(
876876
Ok(msg)
877877
}
878878
Some(Err(err)) => {
879-
if is_incomplete_stream_error(&err) {
879+
if is_forceful_disconnect_error(&err) {
880880
Err(ForcefulDisconnect(err).into())
881881
} else {
882882
// Protocol error: invalid header marker, bad msgpack, unknown command
@@ -901,10 +901,20 @@ async fn recv_command(
901901
}
902902
}
903903

904-
fn is_incomplete_stream_error(err: &io::Error) -> bool {
905-
// tokio_util's FramedRead returns this specific error when EOF is reached
906-
// with bytes still in the decode buffer
907-
err.kind() == io::ErrorKind::Other && err.to_string().contains("bytes remaining on stream")
904+
fn is_forceful_disconnect_error(err: &io::Error) -> bool {
905+
// tokio_util's FramedRead returns this when EOF is reached mid-message.
906+
if err.kind() == io::ErrorKind::Other && err.to_string().contains("bytes remaining on stream") {
907+
return true;
908+
}
909+
matches!(
910+
err.kind(),
911+
// Linux sends ECONNRESET to the peer when a Unix socket is closed while its receive
912+
// buffer is non-empty (unix_release_sock). This is a connectivity issue, not a protocol
913+
// error: the client crashed or was killed after we sent our response.
914+
io::ErrorKind::ConnectionReset |
915+
// EPIPE on a recv is unusual but handle it symmetrically with send_command_resp.
916+
io::ErrorKind::BrokenPipe
917+
)
908918
}
909919

910920
async fn send_command_resp(

appsec/tests/integration/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ def buildTracerCmakeTask = { String version, String variant, altBaseTag = null -
388388
command: [
389389
'-e', '-c',
390390
"""
391-
git config --global --add safe.directory '*'
392391
cd /project/tmp
393392
mkdir -p build_extension/modules
394393
test -f CMakeCache.txt || \\
@@ -485,7 +484,6 @@ def buildTracerSsiCmakeTask = { String version, String variant ->
485484
command: [
486485
'-e', '-c',
487486
"""
488-
git config --global --add safe.directory '*'
489487
cd /tracer-ssi
490488
test -f CMakeCache.txt || \\
491489
cmake -DCMAKE_BUILD_TYPE=${buildType} \\
@@ -567,7 +565,6 @@ def buildAppSecTask = { String version, String variant, altBaseTag = null ->
567565
command: [
568566
'-e', '-c',
569567
"""
570-
git config --global --add safe.directory '*'
571568
cd /appsec
572569
test -f CMakeCache.txt || \\
573570
cmake -DCMAKE_BUILD_TYPE=$buildType \\
@@ -862,8 +859,6 @@ buildRunInDockerTask(
862859
command: [
863860
'-e', '-c',
864861
"""
865-
git config --global --add safe.directory '*'
866-
867862
mkdir -p /tmp/libddwaf-build
868863
cd /tmp/libddwaf-build
869864
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \\
@@ -893,7 +888,6 @@ def helperRustInputs = [
893888
]
894889

895890
def helperRustEnvSetup = '''
896-
git config --global --add safe.directory '*'
897891
export PATH="/root/.cargo/bin:$PATH"
898892
export RUSTUP_HOME=/root/.rustup
899893
export CARGO_HOME=/root/.cargo

0 commit comments

Comments
 (0)