# Particle continuously loops trying to connect: "Event loop error 21"

**URL:** <https://community.particle.io/t/particle-continuously-loops-trying-to-connect-event-loop-error-21/45133>\
**Category:** Troubleshooting\
**Created:** [November 10, 2018, 10:23am UTC](https://community.particle.io/t/particle-continuously-loops-trying-to-connect-event-loop-error-21/45133 "2018-11-10T10:23:22Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![damonmaria](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/damonmaria/32/18279_2.png) [@damonmaria](https://community.particle.io/u/damonmaria)\
**Post date:** [November 11, 2018, 10:56am UTC](https://community.particle.io/t/particle-continuously-loops-trying-to-connect-event-loop-error-21/45133/5 "2018-11-11T10:56:22Z")

</div>

> [@ScruffR](#):
>
> How long are your time constants?

```auto
const system_tick_t TIME_PER_SECOND = 1000;
const system_tick_t TIME_PER_MINUTE = TIME_PER_SECOND * 60;
...
static const system_tick_t IN_PROGRESS_TIMEOUT = 5 * TIME_PER_MINUTE;
static const system_tick_t COMPELTE_TIMEOUT = 10 * TIME_PER_SECOND;

```

The timeout that is always triggered is the `IN_PROGRESS_TIMEOUT`, as per this that I posted a while ago: [How to notify application incase of an incoming OTA update? - #37 by damonmaria](https://community.particle.io/t/how-to-notify-application-incase-of-an-incoming-ota-update/30976/37)

So it's waited 5 minutes before sending the `spark/device/session/end` event. But I see what you're saying / that's made me think: sending the `spark/device/session/end` event may be causing the session to be broken during the processing of that same event? Which causes the error response. Because even tho every `Particle.publish("spark/device/session/end", PRIVATE | WITH_ACK)` returns `false` it does in fact work (the next connect after reboot has to do a full handshake and correctly pulls down the firmware).

So maybe the solution to my problem is to remove the `WITH_ACK`. It's not the end of the world if that event is lost.

> [@ScruffR](#):
>
> BTW, you may have seen millis() timing done as if (millis() - prevTime \> timeout) instead of if (millis() \> nextTime). The reason behind that is explained here

Thanks for the heads up. I'll definitely rearrange things.

---

_[View the full topic](https://community.particle.io/t/particle-continuously-loops-trying-to-connect-event-loop-error-21/45133)._
