Skip to content
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

[MQTT] Wait until connection is established. #3518

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

gichan-jang
Copy link
Member

@gichan-jang gichan-jang commented Oct 12, 2021

Change to wait until the connection is successfully finished within the timeout limit.

This patch fixes the error:
ERROR: MQTTSrc: cb_mqtt_on_connect_failure: failed to connect to the broker: TCP/TLS connect failure.

Test pipeline:
Publisher

$ gst-launch-1.0 videotestsrc is-live=true ! video/x-raw,format=RGB,width=640,height=480,framerate=5/1 ! mqttsink pub-topic=test/videotestsrc

Subscriber

$ gst-launch-1.0 mqttsrc sub-topic=test/videotestsrc ! video/x-raw,format=RGB,width=640,height=480,framerate=5/1 ! videoconvert ! ximagesink

Signed-off-by: gichan gichan2.jang@samsung.com

Self evaluation:

  1. Build test: [ *]Passed [ ]Failed [ ]Skipped
  2. Run test: [ *]Passed [ ]Failed [ ]Skipped

@taos-ci
Copy link
Collaborator

taos-ci commented Oct 12, 2021

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #3518. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://nnstreamer.mooo.com/.

@gichan-jang gichan-jang force-pushed the mqtt/sync branch 2 times, most recently from eb5ce9c to d5d8e97 Compare October 12, 2021 01:16
@@ -551,6 +552,8 @@ gst_mqtt_sink_start (GstBaseSink * basesink)
gchar *haddr = g_strdup_printf ("%s:%s", self->mqtt_host_address,
self->mqtt_host_port);
int ret;
guint timer = 0;
guint tick = DEFAULT_MQTT_SLEEP_TIME_US / 1000U;
Copy link
Collaborator

@again4you again4you Oct 12, 2021

Choose a reason for hiding this comment

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

In my opinion, tick would be DEFAULT_MQTT_SLEEP_TIME_US.
If tick is 1U (i.e.DEFAULT_MQTT_SLEEP_TIME_US / 1000U) , while loop could run 5000 times in case of worst case. If your intent, then it's OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I changed g_cond_wait_until instead of sleep. Please check it again.

gst/mqtt/mqttsrc.c Outdated Show resolved Hide resolved
@taos-ci
Copy link
Collaborator

taos-ci commented Oct 12, 2021

:octocat: cibot: @gichan-jang, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://nnstreamer.mooo.com/nnstreamer/ci/repo-workers/pr-checker/3518-202110121016160.95147395133972-d5d8e971f8e546955f3a893bf640896bb80d7791/.

@@ -586,6 +589,16 @@ gst_mqtt_sink_start (GstBaseSink * basesink)
return FALSE;
}

/* Waiting for the connection */
while (!self->is_connected) {
Copy link
Member

Choose a reason for hiding this comment

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

Q: not communicating with cond?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I updated it. Please check it again.

@gichan-jang
Copy link
Member Author

The mqtt test was modified because the harness could not go to the playing state with the wrong parameter.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@gichan-jang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@gichan-jang, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Member

@anyj0527 anyj0527 left a comment

Choose a reason for hiding this comment

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

LGTM ✔

@myungjoo
Copy link
Member

Questions..
Q1: what happens if TIMEOUT expires with client (subscribers)?
Q2: what happens if TIMEOUT expires with server (publishers)?
Q3: can you justify the answers (the behaviors) of Q1/Q2?
Q4: do you expect (novice) users will be able to "know" what's wrong when this TIMEOUT expires?

Change to wait until connection is successfully established within timeout
limit.

This patch fix the error:
ERROR: MQTTSrc: cb_mqtt_on_connect_failure: failed to connect to the broker: TCP/TLS connect failure.

Test pipeline:
Publisher
```bash
$ gst-launch-1.0 videotestsrc is-live=true ! video/x-raw,format=RGB,width=640,height=480,framerate=5/1 ! mqttsink pub-topic=test/videotestsrc
```
Subscriber
```bash
$ gst-launch-1.0 mqttsrc sub-topic=test/videotestsrc ! video/x-raw,format=RGB,width=640,height=480,framerate=5/1 ! videoconvert ! ximagesink
```

Signed-off-by: gichan <gichan2.jang@samsung.com>
Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
@gichan-jang
Copy link
Member Author

Questions.. Q1: what happens if TIMEOUT expires with client (subscribers)?

If subscriber fails to connect to the broker within the TIMEOUT, it cannot change to playing state and stopped.
I changed to post error message and some guide.

"Failed to connect to MQTT broker from mqttsrc."
"Please check broker is running status or broker host address."

Q2: what happens if TIMEOUT expires with server (publishers)?

Same with subscribers.

Q3: can you justify the answers (the behaviors) of Q1/Q2?

Answered.

Q4: do you expect (novice) users will be able to "know" what's wrong when this TIMEOUT expires?

I add some guide with error message.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@gichan-jang, 💯 All CI checkers are successfully verified. Thanks.

@myungjoo
Copy link
Member

myungjoo commented Oct 25, 2021

Questions.. Q1: what happens if TIMEOUT expires with client (subscribers)?

If subscriber fails to connect to the broker within the TIMEOUT, it cannot change to playing state and stopped. I changed to post error message and some guide.

"Failed to connect to MQTT broker from mqttsrc."
"Please check broker is running status or broker host address."

Q2: what happens if TIMEOUT expires with server (publishers)?

Same with subscribers.

Q3: can you justify the answers (the behaviors) of Q1/Q2?

Answered.

Q4: do you expect (novice) users will be able to "know" what's wrong when this TIMEOUT expires?

I add some guide with error message.

It's ok with subscribers to fail with timeout when publishers do not exist.

However, I still don't understand why publishers need to fail with no subscribers.

We may proceed with this PR, but, publishers (and query servers) definitely need to be able to keep running (either 'paused' or 'dropping at sink') even if there are no subscribers (or query clients) with next PRs.

Imagine you are a server pipeline author and want to start an object detection service for arbitrary IoT devices in TV, Home Hub, or Phone. You don't want to launch pipelines when there is a IoT device connecting for the service; you want to keep running pipelines (server process) and let pipeline wait for incoming IoT devices.

@gichan-jang
Copy link
Member Author

It's ok with subscribers to fail with timeout when publishers do not exist.

However, I still don't understand why publishers need to fail with no subscribers.

We may proceed with this PR, but, publishers (and query servers) definitely need to be able to keep running (either 'paused' or 'dropping at sink') even if there are no subscribers (or query clients) with next PRs.

Imagine you are a server pipeline author and want to start an object detection service for arbitrary IoT devices in TV, Home Hub, or Phone. You don't want to launch pipelines when there is a IoT device connecting for the service; you want to keep running pipelines (server process) and let pipeline wait for incoming IoT devices.

No.. Even without a subscriber, the publisher does not fail.
This change is about the connection to the brokers.
The reason why I made this PR is that the mqtt sink tried to publish the data before it was connected to the broker.
So mqtt elements is to check the connection before publish/subscribe.

@myungjoo myungjoo merged commit 6bb8673 into nnstreamer:main Oct 27, 2021
@gichan-jang gichan-jang deleted the mqtt/sync branch October 28, 2021 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants