{"record":{"id":"481c091677d0ae74","repo":"neondatabase/neon","slug":"unexpected-be-message-kind-in-response-to-getpage","errorCode":null,"errorMessage":"unexpected be message kind in response to getpage request: {}","messagePattern":"unexpected be message kind in response to getpage request: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pageserver/client/src/page_service.rs","lineNumber":241,"sourceCode":"\nimpl PagestreamReceiver {\n    // TODO: maybe make this impl Stream instead for better composability?\n    pub async fn recv(&mut self) -> anyhow::Result<PagestreamBeMessage> {\n        let next: Option<Result<bytes::Bytes, _>> = self.stream.next().await;\n        let next: bytes::Bytes = next.unwrap()?;\n        PagestreamBeMessage::deserialize(next)\n    }\n\n    pub async fn getpage_recv(&mut self) -> anyhow::Result<PagestreamGetPageResponse> {\n        let next: PagestreamBeMessage = self.recv().await?;\n        match next {\n            PagestreamBeMessage::GetPage(p) => Ok(p),\n            PagestreamBeMessage::Error(e) => anyhow::bail!(\"Error: {:?}\", e),\n            PagestreamBeMessage::Exists(_)\n            | PagestreamBeMessage::Nblocks(_)\n            | PagestreamBeMessage::DbSize(_)\n            | PagestreamBeMessage::GetSlruSegment(_) => {\n                anyhow::bail!(\n                    \"unexpected be message kind in response to getpage request: {}\",\n                    next.kind()\n                )\n            }\n            #[cfg(feature = \"testing\")]\n            PagestreamBeMessage::Test(_) => {\n                anyhow::bail!(\n                    \"unexpected be message kind in response to getpage request: {}\",\n                    next.kind()\n                )\n            }\n        }\n    }\n}\n","sourceCodeStart":223,"sourceCodeEnd":256,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/pageserver/client/src/page_service.rs#L223-L256","documentation":"`PagestreamReceiver::getpage_recv` matches on the next backend message and expects `GetPage`; receiving Exists, Nblocks, DbSize, GetSlruSegment (or the testing-only Test variant) means the response kind doesn't pair with the getpage request that was sent. The pagestream protocol is strictly request/response, so this indicates the recv method was mismatched to the request or responses were consumed out of order.","triggerScenarios":"Sending a different request kind (exists/nblocks/dbsize/getslrusegment) but calling `getpage_recv` for the reply; or interleaving multiple requests on one receiver so a later response is read as the getpage answer.","commonSituations":"Copy-pasted client code pairing the wrong send/recv helpers; refactors that changed request order; concurrent access to a single PagestreamReceiver without serialization.","solutions":["Pair each request with its matching recv function (e.g. exists request → exists-style recv, nblocks request → nblocks recv)","Serialize requests on a single pagestream connection: send, recv, then send the next","Use the message's `kind()` in the error output to see which response actually arrived and infer which request it belongs to","Add a debug assertion logging request/response kinds during development"],"exampleFix":"// before: mismatched request/response pairing\npagestream.exists_send(&req).await?;\nlet page = pagestream.getpage_recv().await?; // unexpected be message kind\n\n// after: match recv to the request sent\npagestream.exists_send(&req).await?;\nlet exists = pagestream.exists_recv().await?;","handlingStrategy":"validation","validationCode":"// ensure the response kind matches the request before consuming it\nlet msg = pagestream.recv().await?;\nif msg.kind() != BeaconKind::GetPage {\n    anyhow::bail!(\"expected GetPage response, got {} — check send/recv pairing\", msg.kind());\n}","typeGuard":"fn is_getpage_response(msg: &PagestreamBeMessage) -> bool {\n    matches!(msg, PagestreamBeMessage::GetPage(_))\n}","tryCatchPattern":null,"preventionTips":["Pair every send helper with its matching recv helper; review during code review","Serialize pagestream requests: one in flight per receiver at a time","Log request and response kinds together in debug builds to catch drift early"],"tags":["rust","neon","pageserver","pagestream","protocol"],"backgroundTag":"request-response-mismatch","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}