-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Handle null payloads. #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,10 @@ tl::expected<DataSourceEventHandler::Patch, JsonError> Patch( | |
| if (!data.has_value()) { | ||
| return tl::unexpected(JsonError::kSchemaFailure); | ||
| } | ||
| // Check if the optional is empty (indicates null data) | ||
| if (!data->has_value()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actual root fix. |
||
| return tl::unexpected(JsonError::kSchemaFailure); | ||
| } | ||
| return DataSourceEventHandler::Patch{ | ||
| TStreamingDataKind::Key(path), | ||
| data_model::ItemDescriptor<TData>(data->value())}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #include "streaming_data_source.hpp" | ||
|
|
||
| #include <launchdarkly/network/http_requester.hpp> | ||
|
|
@@ -127,9 +127,18 @@ | |
|
|
||
| client_builder.receiver([weak_self](launchdarkly::sse::Event const& event) { | ||
| if (auto self = weak_self.lock()) { | ||
| self->event_handler_->HandleMessage(event.type(), event.data()); | ||
| // TODO: Use the result of handle message to restart the | ||
| // event source if we got bad data. sc-204387 | ||
| auto status = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secondary handle strange JSON and reconnect. |
||
| self->event_handler_->HandleMessage(event.type(), event.data()); | ||
| if (status == DataSourceEventHandler::MessageStatus::kInvalidMessage) { | ||
| // Invalid data received - restart the connection with backoff | ||
| // to get a fresh stream. The backoff mechanism prevents rapid | ||
| // reconnection attempts. | ||
| LD_LOG(self->logger_, LogLevel::kWarn) | ||
| << "Received invalid data from stream, restarting connection"; | ||
| if (self->client_) { | ||
| self->client_->async_restart("invalid data in stream"); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we just restart the stream when we encounter invalid JSON, then we could create a thundering-herd in the case the service somehow sent invalid JSON. So we defer the restart to the event source implementation. Which allows for it to incorporate back-off. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All tests now pass, so no suppressions are needed.