# cleanStart=false on reconnect

**URL:** <https://community.hivemq.com/t/cleanstart-false-on-reconnect/2770>\
**Category:** HiveMQ Client Library\
**Created:** [March 13, 2024, 7:19am UTC](https://community.hivemq.com/t/cleanstart-false-on-reconnect/2770 "2024-03-13T07:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://community.hivemq.com/u/jonathan)\
**Post date:** [March 13, 2024, 7:19am UTC](https://community.hivemq.com/t/cleanstart-false-on-reconnect/2770/1 "2024-03-13T07:19:51Z")

</div>

How do you specify that you want the client to auto reconnect with cleanStart=false? My initial connection is correct with cleanStart=false, but when I force a disconnect of my client form the control center the default reconnect behavior reconnects the client with cleanStart=true.

What do have to changer here:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/111edd22fbc2df0200a77c145a3b3629ba3f17e4.png)

or maybe I need to implement some custom listener code here:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/bfa536fce872038a9edcaab84bbde0c71cf00935.png)

or maybe here:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/8acae171cdab8d374539b670efbac512bad8e4c6.png)

---

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://community.hivemq.com/u/jonathan)\
**Post date:** [March 13, 2024, 5:39pm UTC](https://community.hivemq.com/t/cleanstart-false-on-reconnect/2770/2 "2024-03-13T17:39:16Z")

</div>

I was able to figure out the solution. On the connection builder you need to add .noSessionExpiry(). This way the session will stay active on the broker and when the client auto reconnects the session config cleanStart=False is retained.

---

<div class="post-metadata">

**Author:** ![AaronTLFranz](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/aarontlfranz/32/638_2.png) [@AaronTLFranz](https://community.hivemq.com/u/AaronTLFranz)\
**Post date:** [March 13, 2024, 6:03pm UTC](https://community.hivemq.com/t/cleanstart-false-on-reconnect/2770/3 "2024-03-13T18:03:12Z")

</div>

Hello @jonathan ,

Thank you for the outreach!

That is absolutely correct - adding `.noSessionExpiry()` will implement the a cleanStart = false for MQTT5 clients.

This is a result of an evolution with MQTT5 of the cleanStart feature now using a sessionExpiry value. Some additional details regarding the MQTT5 sessionExpiry can be found in our MQTT Essentials articles [here](https://www.hivemq.com/blog/mqtt5-essentials-part4-session-and-message-expiry/). Some additional examples of reconnect strategies using the HiveMQ MQTT Java client, which I believe to be the client in use here, can be found within our examples directory on the client GitHub page [here](https://github.com/hivemq/hivemq-mqtt-client/blob/master/examples/src/main/java/com/hivemq/client/mqtt/examples/ReconnectStrategy.java).

Best,  
Aaron from the HiveMQ Team
