check for MDBX_PANIC

This commit is contained in:
Bryan Stitt 2023-10-09 09:38:58 -07:00
parent d1d5e8ecf5
commit ab16f6b2e8
2 changed files with 36 additions and 11 deletions

View File

@ -98,6 +98,9 @@ pub enum Web3ProxyError {
#[display(fmt = "{:?}", _0)] #[display(fmt = "{:?}", _0)]
#[error(ignore)] #[error(ignore)]
JsonRpcErrorData(JsonRpcErrorData), JsonRpcErrorData(JsonRpcErrorData),
#[from(ignore)]
#[display(fmt = "{}", _0)]
MdbxPanic(String, Cow<'static, str>),
NoBlockNumberOrHash, NoBlockNumberOrHash,
NoBlocksKnown, NoBlocksKnown,
NoConsensusHeadBlock, NoConsensusHeadBlock,
@ -199,6 +202,7 @@ impl Web3ProxyError {
/// turn the error into an axum response. /// turn the error into an axum response.
/// <https://www.jsonrpc.org/specification#error_object> /// <https://www.jsonrpc.org/specification#error_object>
/// TODO? change to `to_response_parts(self)`
pub fn as_response_parts(&self) -> (StatusCode, JsonRpcResponseEnum<Arc<RawValue>>) { pub fn as_response_parts(&self) -> (StatusCode, JsonRpcResponseEnum<Arc<RawValue>>) {
// TODO: include a unique request id in the data // TODO: include a unique request id in the data
let (code, err): (StatusCode, JsonRpcErrorData) = match self { let (code, err): (StatusCode, JsonRpcErrorData) = match self {
@ -642,6 +646,20 @@ impl Web3ProxyError {
// TODO: do this without clone? the Arc needed it though // TODO: do this without clone? the Arc needed it though
(StatusCode::OK, jsonrpc_error_data.clone()) (StatusCode::OK, jsonrpc_error_data.clone())
} }
Self::MdbxPanic(rpc, msg) => {
error!(%msg, "mdbx panic");
// TODO: this is bad enough that we should send something to pager duty
(
StatusCode::INTERNAL_SERVER_ERROR,
JsonRpcErrorData {
message: "mdbx panic".into(),
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(),
data: Some(serde_json::Value::String(msg.to_string())),
},
)
}
Self::MethodNotFound(method) => { Self::MethodNotFound(method) => {
warn!("MethodNotFound: {}", method); warn!("MethodNotFound: {}", method);
( (

View File

@ -383,17 +383,24 @@ impl OpenRequestHandle {
match error.code { match error.code {
-32000 => { -32000 => {
// TODO: regex? if error.message.contains("MDBX_PANIC:") {
let archive_prefixes = [ response = Err(Web3ProxyError::MdbxPanic(
"header not found", self.connection_name(),
"header for hash not found", error.message.clone(),
"missing trie node", ));
]; } else {
for prefix in archive_prefixes { // TODO: regex?
if error.message.starts_with(prefix) { let archive_prefixes = [
// TODO: what error? "header not found",
response = Err(Web3ProxyError::NoBlockNumberOrHash); "header for hash not found",
break; "missing trie node",
];
for prefix in archive_prefixes {
if error.message.starts_with(prefix) {
// TODO: what error?
response = Err(Web3ProxyError::NoBlockNumberOrHash);
break;
}
} }
} }
} }