Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: 4ecd3c0fb7625a101992d68e14946eba15f65a27
Timestamp: Wed, 04 Sep 2024 09:09:02 +0000 (3 months ago)

+15 -1 +/-2 browse
handle rejection fatal errors by closing connection
1diff --git a/maitred/src/server.rs b/maitred/src/server.rs
2index 4d668d1..78aa2ea 100644
3--- a/maitred/src/server.rs
4+++ b/maitred/src/server.rs
5 @@ -180,7 +180,11 @@ impl Server {
6 }
7 Err(e) => {
8 tracing::warn!("Client error: {:?}", e);
9+ let fatal = e.is_fatal();
10 framed.send(e).await?;
11+ if fatal {
12+ break 'outer;
13+ }
14 }
15 }
16 }
17 @@ -195,6 +199,7 @@ impl Server {
18 }
19 Err(response) => {
20 tracing::warn!("Error handling message payload: {:?}", response);
21+
22 framed.send(response).await?;
23 }
24 }
25 diff --git a/maitred/src/transport.rs b/maitred/src/transport.rs
26index 3d11cdc..0c5c0ad 100644
27--- a/maitred/src/transport.rs
28+++ b/maitred/src/transport.rs
29 @@ -30,6 +30,15 @@ where
30 Ehlo(EhloResponse<T>),
31 }
32
33+ impl Response<String> {
34+ pub fn is_fatal(&self) -> bool {
35+ match self {
36+ Response::General(resp) => resp.code >= 500,
37+ Response::Ehlo(_) => false,
38+ }
39+ }
40+ }
41+
42 impl<T> PartialEq for Response<T>
43 where
44 T: Display,
45 @@ -175,7 +184,7 @@ impl Decoder for Transport {
46 match r.ingest(&mut iter, src) {
47 Ok(request) => {
48 if !requests.is_empty() && !self.pipelining {
49- return Err(TransportError::PipelineNotEnabled)
50+ return Err(TransportError::PipelineNotEnabled);
51 }
52 requests.push(request);
53 }