Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Linux] Allow BasicMessageChannel sending and responding to null message #42808

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Jun 13, 2023

Description

This PR changes how a null message is handled by the Linux engine for a basic message channel.

Before:

  • when receiving a null message a warning was emitted.
  • fl_binary_messenger_send_response was called but failed and the application exited.
** (bug:9866): WARNING **: 23:13:42.109: Failed to decode message: Unexpected end of data

** (bug:9866): CRITICAL **: 23:13:42.109: gboolean send_response(FlBinaryMessenger *, FlBinaryMessengerResponseHandle *, GBytes *, GError **): assertion 'response_handle->response_handle != nullptr' failed

After:

  • Receiving a null message is handled as expected from the framework side documentation:

https://github.com/flutter/flutter/blob/9287e81d52d69560222c14170a2fd7def613fe61/packages/flutter/lib/src/services/platform_channel.dart#L149-L150

Related Issue

Fixes flutter/flutter#128704

Tests

Adds 2 tests.

@bleroux bleroux force-pushed the fix_linux_basic_message_channel_should_allow_null_message branch 2 times, most recently from 249c8b0 to 2044ef9 Compare June 14, 2023 09:53
@@ -232,7 +232,6 @@ G_MODULE_EXPORT void fl_basic_message_channel_send(FlBasicMessageChannel* self,
GAsyncReadyCallback callback,
gpointer user_data) {
g_return_if_fail(FL_IS_BASIC_MESSAGE_CHANNEL(self));
g_return_if_fail(message != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mean calling fl_message_codec_encode_message with null below; does that work? Is there unit testing of it? Does it return a non-null data pointer, such that line 246 won't return an error?

Copy link
Contributor Author

@bleroux bleroux Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mean calling fl_message_codec_encode_message with null below; does that work?

Yes, I have checked that fl_message_codec_encode_message allow null message, it properly replaces it with fl_value_new_null() :

g_autoptr(FlValue) null_value = nullptr;
if (message == nullptr) {
null_value = fl_value_new_null();
message = null_value;
}

Is there unit testing of it?

I think this is covered by those tests:

TEST(FlStandardMessageCodecTest, EncodeNullptr) {
g_autofree gchar* hex_string = encode_message(nullptr);
EXPECT_STREQ(hex_string, "00");
}
TEST(FlStandardMessageCodecTest, EncodeNull) {
g_autoptr(FlValue) value = fl_value_new_null();
g_autofree gchar* hex_string = encode_message(value);
EXPECT_STREQ(hex_string, "00");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add '(allow-none)' to the documentation string in public/flutter_linux/fl_basic_message_channel.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add '(allow-none)' to the documentation string in public/flutter_linux/fl_basic_message_channel.h

Done, thanks for noticing this 👍

@@ -420,6 +420,10 @@ static GBytes* fl_standard_message_codec_encode_message(FlMessageCodec* codec,
static FlValue* fl_standard_message_codec_decode_message(FlMessageCodec* codec,
GBytes* message,
GError** error) {
if (g_bytes_get_size(message) == 0) {
return fl_value_new_null();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbracken Null messages strike again :P

How do you think we should handle null messages here: null data, or a value whose value is null? IIRC you found that this was inconsistent in #25064 but I forget whether you cleaned it up later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to return the FlValue object here, because returning NULL implies there was an error (GObject convention).

Copy link
Contributor

@robert-ancell robert-ancell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the docstring change this looks good, on the assumption that this is the correct behaviour for receiving an empty message.

@bleroux bleroux force-pushed the fix_linux_basic_message_channel_should_allow_null_message branch from 2044ef9 to 20e5b55 Compare June 15, 2023 06:16
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 15, 2023
@auto-submit auto-submit bot merged commit 9cdecd8 into flutter:main Jun 15, 2023
@bleroux bleroux deleted the fix_linux_basic_message_channel_should_allow_null_message branch June 15, 2023 14:09
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 15, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 15, 2023
…128959)

flutter/engine@9934c0d...48e0b4e

2023-06-15 [email protected] Roll Skia from 0b66c6928dcf to 2d531d020c26 (3 revisions) (flutter/engine#42883)
2023-06-15 [email protected] Raster cache should preserve RTree for overlay layers (flutter/engine#42552)
2023-06-15 [email protected] Roll Skia from c0c74b433117 to 0b66c6928dcf (1 revision) (flutter/engine#42879)
2023-06-15 [email protected] [Linux] Allow BasicMessageChannel sending and responding to null message (flutter/engine#42808)
2023-06-15 [email protected] Roll Skia from 12375fb6f3c8 to c0c74b433117 (1 revision) (flutter/engine#42876)
2023-06-15 [email protected] Roll Skia from d62221bd33a6 to 12375fb6f3c8 (1 revision) (flutter/engine#42873)
2023-06-15 [email protected] Roll Skia from e2e0256d4c6a to d62221bd33a6 (1 revision) (flutter/engine#42871)
2023-06-15 [email protected] Roll Skia from c3abd540c7f9 to e2e0256d4c6a (1 revision) (flutter/engine#42869)
2023-06-15 [email protected] Roll Fuchsia Linux SDK from uvmDF7KM34dWGdsuK... to 53EjCyuRu91oFTBf2... (flutter/engine#42868)
2023-06-15 [email protected] Roll Fuchsia Mac SDK from h3-8RUVrC889UXou7... to P7QA6bfO_Ij5dre7B... (flutter/engine#42867)
2023-06-15 [email protected] Roll Skia from 2718866006d2 to c3abd540c7f9 (1 revision) (flutter/engine#42866)
2023-06-15 [email protected] Roll Skia from 19051bc5fc90 to 2718866006d2 (33 revisions) (flutter/engine#42864)
2023-06-15 [email protected] Roll Dart SDK from 922c315b2c34 to 8eaed3382237 (1 revision) (flutter/engine#42862)
2023-06-15 [email protected] Add missing artifact to the android_arm64_profile config. (flutter/engine#42858)
2023-06-14 [email protected] Build skia with expat (flutter/engine#42859)
2023-06-14 [email protected] [ios] use interfaceOrientation orientation on iOS 13 and above (flutter/engine#42846)
2023-06-14 [email protected] Manual roll Dart SDK from f1387834bfd9 to 922c315b2c34 (4 revisions) (flutter/engine#42855)
2023-06-14 [email protected] [Impeller] Make interleaved layout (more) explicit in generated headers. (flutter/engine#42628)
2023-06-14 [email protected] Renamed validation layers build (flutter/engine#42826)
2023-06-14 [email protected] [ios] view controller based status bar (flutter/engine#42643)
2023-06-14 [email protected] Roll Skia from 6d5dc31d88e2 to 19051bc5fc90 (25 revisions) (flutter/engine#42828)
2023-06-14 [email protected] Roll Fuchsia Linux SDK from Xi3c5nti2LKnEOqYt... to uvmDF7KM34dWGdsuK... (flutter/engine#42842)
2023-06-14 [email protected] Fix generateLockfiles running directory for documentation (flutter/engine#42734)
2023-06-14 [email protected] Roll Fuchsia Mac SDK from Cld7-rm6ZmCOO8j-K... to h3-8RUVrC889UXou7... (flutter/engine#42839)
2023-06-14 [email protected] Roll ANGLE from 7e075469ff02 to 3a3a3c655a96 (8 revisions) (flutter/engine#42834)
2023-06-14 [email protected] Roll Dart SDK from c4e9794df8af to f1387834bfd9 (1 revision) (flutter/engine#42833)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Xi3c5nti2LKn to 53EjCyuRu91o
  fuchsia/sdk/core/mac-amd64 from Cld7-rm6ZmCO to P7QA6bfO_Ij5

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Linux] flutter basic message channel should accept null message
3 participants