Commit Graph
79 Commits
Author SHA1 Message Date
Mathieu Carbou 269124956a Applying clang formatting 2024-12-15 16:51:34 +01:00
Emil Muratov 7bfbb947d0 queue deadlock and congestion aviodance
- do not let `_remove_events_with_arg()` call to block on queue pertubation, otherwise it could deadlock

 - in any case do not block on adding LWIP_TCP_POLL event to the queue, it does not make much sense anyway
   due to poll events are repetitive

 - `_get_async_event()` will discard LWIP_TCP_POLL events when q gets filled up
   this will work in combination with throttling poll events when adding to the queue
   Poor designed apps and multiple parallel connections could flood the queue with interleaved poll events
   that can't be properly throttled or coalesced. So we can discard it in the eviction task after coalescing
   It will work in this way:
    - queue is up to 1/4 full - all events are entering the queue and serviced
    - queue is from 1/4 and up to 3/4 full - new poll events are throttled on enqueue with linear probability
    - queue is from 3/4 up to full top - all new poll events are ignored on enqueue and existing poll events
      already in the queue are discarded on eviction with linear probability giving away priority for all other
      events to be serviced. It is expected that on a new poll timer connection polls could reenter the queue
2024-12-15 17:25:29 +09:00
Emil Muratov 80b2733de5 make _async_service_task's watchdog constantly watching with periodic feed 2024-12-15 10:20:55 +09:00
Emil Muratov afa162b73a Coalesce poll events on queue eviction
Refer: https://github.com/mathieucarbou/ESPAsyncWebServer/discussions/165

Let's try to coalesce two (or more) consecutive poll events into one
this usually happens with poor implemented user-callbacks that are runs too long and makes poll events to stack in the queue
if consecutive user callback for a same connection runs longer that poll time then it will fill the queue with events until it deadlocks.
This is a workaround to mitigate such poor designs and won't let other events/connections to starve the task time.
It won't be effective if user would run multiple simultaneous long running callbacks due to message interleaving.
todo: implement some kind of fair dequeing or (better) simply punish user for a bad designed callbacks by resetting hog connections
2024-12-13 16:32:15 +09:00
Mathieu Carbou 31b3452efb Code reformat according to clang file 2024-12-11 19:55:13 +01:00
Mathieu Carbou 8302dba2b8 Issue 169 2024-12-11 15:02:55 +01:00
Emil Muratov ba3fa2a2ca throttle polling events when message queue gets filled up
a proof of concept, might help on long/large responces with user callbacks

(cherry picked from commit 18bbb3318547bde7a34a84229227ea1f5b80cc72)
2024-12-11 11:34:51 +01:00
Mathieu Carbou e48f2a5db8 Fix missing lock/unlock around dns_gethostbyname 2024-12-10 22:44:18 +01:00
Mathieu Carbou d250960259 Fix: Required to lock TCPIP core functionality
See: https://github.com/espressif/arduino-esp32/issues/10526#issuecomment-2471122550
2024-11-12 18:43:58 +01:00
Mathieu Carbou 45b7ee826b Fix #27: Required to lock TCPIP core functionality 2024-10-27 08:37:58 +01:00
Mathieu Carbou bad4972734 Fix #27: Required to lock TCPIP core functionality
Ref:
- https://github.com/mathieucarbou/AsyncTCP/issues/27
- https://github.com/espressif/arduino-esp32/issues/10526
2024-10-26 12:30:38 +02:00
Mathieu Carbou d198248240 Fix _recv method 2024-10-13 11:28:15 +02:00
Mathieu Carbou 784df13d4b Try fix #26 again 2024-10-13 10:05:12 +02:00
Mathieu Carbou b4a974dc31 Fix #26 2024-10-12 20:55:11 +02:00
Mathieu Carbou c3f2188901 Rollback #18 2024-10-02 22:57:58 +02:00
Mathieu Carbou 4837967b64 Introduced macro INVALID_CLOSED_SLOT 2024-10-02 22:56:41 +02:00
Mathieu Carbou 5093f8dbcd Changed numbers to enum for _pcb->state 2024-09-09 22:25:40 +02:00
David Woodhouse 95de78acbb Use IPADDR6_INIT() macro to set connecting IPv6 address
If LwIP is built with LWIP_IPV6_SCOPES, there is a 'zone' member in
struct ip6_addr which was not being initialized correctly, leading to
routing failures.

The tcp_connect() call would return ERR_RTE and we would completely fail
to report that error. All the user would see is 'Connecting to MQTT...'
over and over again.
2024-09-02 15:31:44 +02:00
Mathieu Carbou f374fabaa2 Fix link 2024-07-29 18:55:03 +02:00
Mathieu Carbou b20e646658 Try fix #14 2024-07-29 18:55:03 +02:00
Mathieu Carbou 018e8ae8b6 Try remove busy loop to fix https://github.com/mathieucarbou/ESPAsyncWebServer/issues/57 2024-07-17 21:42:18 +02:00
Mathieu Carbou 15581b57ec Arduino 3.0.3 compatibility 2024-07-17 15:57:37 +02:00
Mathieu Carbou acdf1f5e71 Revert "Try fix from https://github.com/me-no-dev/AsyncTCP/pull/173/files#r1581612715"
This reverts commit c174f6c467.
2024-07-16 22:54:24 +02:00
Mathieu Carbou c174f6c467 Try fix from https://github.com/me-no-dev/AsyncTCP/pull/173/files#r1581612715 2024-07-16 22:16:25 +02:00
Mathieu Carbou f0319ac64e Add fix from https://github.com/me-no-dev/AsyncTCP/pull/184 2024-07-04 12:14:45 +02:00
Mathieu Carbou b572c1e969 Fix for https://github.com/mathieucarbou/ESPAsyncWebServer/issues/26 2024-05-30 01:30:32 +02:00
Mathieu Carbou b1df6526c1 IPv6 cleanups 2024-05-30 00:34:01 +02:00
Mathieu Carbou 212780ced1 Reduce logging of non critical messages 2024-04-27 14:17:23 +02:00
Mathieu Carbou 65b4e998c7 Grab fixes from https://github.com/me-no-dev/AsyncTCP/pull/173 2024-04-27 12:31:07 +02:00
Mathieu Carbou 85988d5a44 CONFIG_ASYNC_TCP_MAX_ACK_TIME 2024-04-27 12:20:28 +02:00
Mathieu Carbou ec5d01ed59 code cleanup 2024-04-27 01:17:55 +02:00
Mathieu Carbou db8cfa1ee7 Add setKeepAlive() 2024-04-27 01:17:55 +02:00
Mathieu Carbou de284cc5cc Add CONFIG_ASYNC_TCP_QUEUE_SIZE 2024-04-27 01:17:55 +02:00
Mathieu Carbou 0227108fc4 Add CONFIG_ASYNC_TCP_PRIORITY 2024-04-27 01:17:55 +02:00
Mathieu Carbou 482cddd835 Remove warning 2024-04-20 12:20:45 +02:00
Mathieu Carbou ea3ebd7289 Do not rely on configENABLE_BACKWARD_COMPATIBILITY 2024-04-20 11:14:17 +02:00
Mathieu Carbou c4cb7653fe Arduino 3 / ESP IDF 5 compatibility 2024-04-19 22:43:05 +02:00
Jimmy Hedman 2ae3787c71 Fixes libretiny (#10) 2024-02-19 08:08:25 +13:00
Jimmy Hedman bf3e4d23f3 Rework CI and fix an error (#6) 2024-01-18 08:13:53 +09:00
Jimmy HedmanandPaweł pidpawel Kozubal 42a8644bb2 IPv6 support added (#5)
Co-authored-by: Paweł pidpawel Kozubal <pawel.kozubal@husarnet.com>
2023-12-21 12:59:30 +09:00
Kuba Szczodrzyński fb0411b699 Adapt for LibreTuya compatibility (#3) 2022-08-09 17:34:14 +12:00
Maurice Makaay 18ac673e82 Define one_day var as a const. 2021-05-06 00:41:06 +02:00
Maurice Makaay 6f379678f0 Better fix for "ack timeout 4" client disconnects.
After my first attempt at fixing the client disconnects
(https://github.com/OttoWinter/AsyncTCP/pull/4) got merged
into AsyncTCP, it turned out that there was regression
for some devices: the connection stability actually went
down instead of up.

After a lot of debugging and discussion with @glmnet (some of
the results can be found in the above pull request discussion),
we came up with an improved fix for the disconnect issues.

**Changed:**

The code that checks for ACK timeouts has been simplified in
such way, that only two timestamps are now used to determine if
an ACK timeout has happened: the time of the last sent packet
(this was already recorded), and the time of the last received
ACK from the client (this has been added).

Using these timestamps, there is no more need for a separate field
to keep track if we are waiting for an ACK or not (`_pcb_busy`).
Therefore, this field was completely removed from the code.

While I was at it, I renamed a few variables to make the code
easier to read and more consistent.

**Results:**

I connected Home Assistant plus 8 OTA loggers at the same time,
using very verbose logging output. This normally was an easy way
to trigger the disconnect errors.

It turned out, this solution runs as solid for me, as when disabling
the ACK timeout checks completely
(using `AsyncClient::setAckTimeout(0)`).
2021-05-05 23:56:48 +02:00
Maurice MakaayandMaurice Makaay 030b747616 Fix race condition causing 'ack timeout 4' disconnects (#4)
The AsyncClient::send() methods sets a boolean to true after pushing
data over the TCP socket successfully using tcp_output(). It also sets
a timestamp to remember at what time the data was sent.

The AsyncClient::_sent() callback method reacts to ACKs coming from
the connected client. This method sets the boolean to false.

In the AsyncClient::_poll() method, a check is done to see if the
boolean is true ("I'm waiting for an ACK") and if the time at which
the data was sent is too long ago (5000 ms). If this is the case,
a connection issue with the connected client is assumed and the
connection is forcibly closed by the server.

The race condition is when these operations get mixed up, because
of multithreading behavior. The _sent() method can be called during
the execution of the send() method:

1. send() sends out data using tcp_output()
2. _sent() is called because an ACK is processed, sets boolean to false
3. send() continues and sets boolean to true + timestamp to "now"

After this, the data exchange with the client was successful. Data were
sent and the ACK was seen.
However, the boolean ended up as true, making the _poll() method think
that an ACK is still to be expected. As a result, 5000 ms later, the
connection is dropped.

This commit fixes the code by first registering that an ACK is
expected, before calling tcp_output(). This way, there is no race
condition when the ACK is processed right after that call.

Additionally, I changed the boolean to an integer counter value.
The server might send multiple messages to the client, resulting in
multiple expected ACKs. A boolean does not cover this situation.

Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
2021-04-11 19:09:21 +02:00
Otto winter d2fec0cb7e Merge remote-tracking branch 'upstream/master' 2021-04-08 15:30:32 +02:00
Bob ca8ac5f919 Fix LoadProhibited (#73) 2019-10-17 10:08:59 +03:00
matt123p cacac8f871 Make sure the closed slot is always freed (#68)
* Tidy up and fix some edge cases.

* Make sure we always release a closed_slot.
2019-10-14 22:38:04 +03:00
Bob d27a12ace6 Fix assertion errors (#72)
* Fix assertion errors

* Add state check

* replace tabs with spaces
2019-10-14 22:25:27 +03:00
Otto Winter c18b7cafcc Create fallback xTaskCreateUniversal function 2019-10-14 12:46:51 +02:00
Matt 1a15dfd17f Add thread safety around choosing a closed_slot. 2019-09-24 19:00:02 +01:00