lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #59049] MQTT in FreeRTOS tasks give error on TCP-write


From: Andre
Subject: [lwip-devel] [bug #59049] MQTT in FreeRTOS tasks give error on TCP-write/output
Date: Tue, 1 Sep 2020 07:48:50 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0

URL:
  <https://savannah.nongnu.org/bugs/?59049>

                 Summary: MQTT in FreeRTOS tasks give error on
TCP-write/output
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: klaasvortex
            Submitted on: Tue 01 Sep 2020 11:48:49 AM UTC
                Category: Contrib
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: 2.1.1

    _______________________________________________________

Details:

When using MQTT to sent data from *seperate* threads (FreeRTOS) I got errors
on LWIP. (and sometimes deadlocks in loops)

==
I am using MQTT to sent logging from multiple tasks to a MQTT server. My own
Logging writing function is protected by mutex and is thread safe. 

However the LWIP-thread is NOT the same as my Logging thread. This gives
(occasionly) errors on LWIP-tcp-write and output functions.

Looking into mqtt.c, the public publish sub/un sub function do both call 

  *mqtt_output_send(&client->output, client->conn);* 

Which use tcp->write/output. This will cause the fault. Since these functions
are not protected (thread safe)and should only be called from the LWIP thread.
(I think)

Remember the publish/sub.unsub functions copy the data into a ringbuffer. Then
the sent function will transmit the ringbuffer data. So we can use this buffer
to do the next thing.

By removing the mqtt_output_send from these 2 public mqtt-functions, the
errors are gone and everything works. Since the tcp->poll function will take
over the transmission and is called from the LWIP-task. The poll function will
transmit any data from the ringbuffer.

But there will be a delay before sending since it is started when the poll
runs and not directly sent after call pusblish.

Subscribtions are no problem since they are called from the LWIP thread.


With this solution I can call mqtt_publish from every task. Which I would like
to do.

But I am not sure if this is the correct way to do so. 

Is there a better way to do this ?















    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?59049>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]