Skip to content

Commit

Permalink
Bump kawa and log parsing errors
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed Nov 15, 2023
1 parent 75b8abd commit 8354417
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hdrhistogram = "^7.5.2"
hex = "^0.4.3"
hpack = "^0.3.0"
idna = "^0.4.0"
kawa = { version = "^0.6.3", default-features = false }
kawa = { version = "^0.6.4", default-features = false }
libc = "^0.2.149"
memchr = "^2.6.4"
mio = { version = "^0.8.8", features = ["os-poll", "os-ext", "net"] }
Expand Down Expand Up @@ -68,7 +68,7 @@ logs-debug = []
logs-trace = []
simd = ["kawa/simd"]
splice = []
tolerant-http1-parser = []
tolerant-http1-parser = ["kawa/tolerant-parsing"]
unstable = []

[badges]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl ProxySession for HttpSession {
return;
}

debug!("Closing HTTP session");
trace!("Closing HTTP session");
self.metrics.service_stop();

// Restore gauges
Expand Down
36 changes: 34 additions & 2 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,24 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
incr!("http.requests");
}

if self.request_stream.is_error() {
if let kawa::ParsingPhase::Error { marker, kind } = self.request_stream.parsing_phase {
incr!("http.frontend_parse_errors");
debug!(
"{} Parsing request error in {:?}: {}",
self.log_context(),
marker,
match kind {
kawa::ParsingErrorKind::Consuming { index } => {
let kawa = &self.request_stream;
parser::view(
kawa.storage.used(),
16,
&[kawa.storage.head, index as usize],
)
}
kawa::ParsingErrorKind::Processing { message } => message.to_owned(),
}
);
if self.response_stream.consumed {
return StateResult::CloseSession;
} else {
Expand Down Expand Up @@ -661,8 +677,24 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
kawa::h1::parse(&mut self.response_stream, &mut self.context);
// kawa::debug_kawa(&self.response_stream);

if self.response_stream.is_error() {
if let kawa::ParsingPhase::Error { marker, kind } = self.response_stream.parsing_phase {
incr!("http.backend_parse_errors");
debug!(
"{} Parsing request error in {:?}: {}",
self.log_context(),
marker,
match kind {
kawa::ParsingErrorKind::Consuming { index } => {
let kawa = &self.request_stream;
parser::view(
kawa.storage.used(),
16,
&[kawa.storage.head, index as usize],
)
}
kawa::ParsingErrorKind::Processing { message } => message.to_owned(),
}
);
if self.response_stream.consumed {
return SessionResult::Close;
} else {
Expand Down
36 changes: 35 additions & 1 deletion lib/src/protocol/kawa_h1/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, str::from_utf8_unchecked};
use std::{fmt::{self, Write}, str::from_utf8_unchecked};

use nom::{
bytes::{self, complete::take_while},
Expand Down Expand Up @@ -113,3 +113,37 @@ pub fn hostname_and_port(i: &[u8]) -> IResult<&[u8], (&[u8], Option<&[u8]>)> {
}
Ok((i, (host, port)))
}

pub fn view(buf: &[u8], size: usize, points: &[usize]) -> String {
let mut view = String::new();
let mut end = 0;
for (i, point) in points.iter().enumerate() {
let start = if end + size < *point {
view.push_str("... ");
point - size
} else {
end
};
let stop = if i + 1 < points.len() {
points[i + 1]
} else {
buf.len()
};
end = if point + size > stop {
stop
} else {
point + size
};
for element in &buf[start..*point] {
let _ = view.write_fmt(format_args!("{element:02X} "));
}
view.push_str("| ");
for element in &buf[*point..end] {
let _ = view.write_fmt(format_args!("{element:02X} "));
}
}
if end < buf.len() {
view.push_str("...")
}
view
}
2 changes: 1 addition & 1 deletion lib/src/router/pattern_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<V: Debug + Clone> TrieNode<V> {

match self.children.get_mut(suffix) {
Some(child) => match child.remove_recursive(prefix) {
RemoveResult::NotFound => return RemoveResult::NotFound,
RemoveResult::NotFound => RemoveResult::NotFound,
RemoveResult::Ok => {
if child.is_empty() {
self.children.remove(suffix);
Expand Down

0 comments on commit 8354417

Please sign in to comment.