Skip to content

Commit de79958

Browse files
committed
fix: preserve FDv2 protocol state across error events
1 parent 283e172 commit de79958

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

libs/internal/src/fdv2_protocol_handler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ FDv2ProtocolHandler::Result FDv2ProtocolHandler::HandleError(
163163
boost::json::value const& data) {
164164
auto result = boost::json::value_to<
165165
tl::expected<std::optional<FDv2Error>, JsonError>>(data);
166-
Reset();
166+
// Discard any partial-payload accumulation but keep state intact so
167+
// the next put-object/payload-transferred cycle continues normally.
168+
changes_.clear();
167169
if (!result) {
168170
return Error::JsonParseError(result.error(),
169171
"could not deserialize error event");

libs/internal/tests/fdv2_protocol_handler_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@ TEST(FDv2ProtocolHandlerTest,
235235
EXPECT_TRUE(cs->changes.empty());
236236
}
237237

238+
TEST(FDv2ProtocolHandlerTest, ErrorMidPayloadDiscardsPartialAcceptsSubsequent) {
239+
FDv2ProtocolHandler handler;
240+
241+
handler.HandleEvent("server-intent", MakeServerIntent("xfer-full"));
242+
handler.HandleEvent("put-object",
243+
MakePutObject("flag", "abandoned", kFlagJson));
244+
handler.HandleEvent(
245+
"error", boost::json::parse(R"({"reason":"something went wrong"})"));
246+
247+
// After the error, a fresh put + payload-transferred (without an
248+
// intervening server-intent) emits a changeset containing only the
249+
// post-error put.
250+
handler.HandleEvent("put-object",
251+
MakePutObject("flag", "fresh", kFlagJson));
252+
auto result = handler.HandleEvent("payload-transferred",
253+
MakePayloadTransferred("s", 1));
254+
255+
auto* cs = std::get_if<data_model::FDv2ChangeSet>(&result);
256+
ASSERT_NE(cs, nullptr);
257+
ASSERT_EQ(cs->changes.size(), 1u);
258+
EXPECT_EQ(cs->changes[0].key, "fresh");
259+
}
260+
238261
TEST(FDv2ProtocolHandlerTest, ErrorEventWithIdSetsServerId) {
239262
FDv2ProtocolHandler handler;
240263

0 commit comments

Comments
 (0)