# Python client reconnection failure

**URL:** <https://community.solace.com/t/python-client-reconnection-failure/1196>\
**Category:** General Discussions\
**Created:** [March 24, 2022, 4:59pm UTC](https://community.solace.com/t/python-client-reconnection-failure/1196 "2022-03-24T16:59:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergkr21](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sergkr21](https://community.solace.com/u/sergkr21)\
**Post date:** [March 24, 2022, 4:59pm UTC](https://community.solace.com/t/python-client-reconnection-failure/1196/1 "2022-03-24T16:59:51Z")

</div>

> Hi,  
> I use Python package solace-pubsubplus v 1.2.0 to connect to Solace. My client has the following reconnection settings: reconnect retries = 20 and reconnect retry wait = 3000 ms. Here is my code for that:  
> messaging\_service = MessagingService.builder().from\_properties(broker\_props)   
> .with\_reconnection\_retry\_strategy(RetryStrategy.parametrized\_retry(20, 3000))   
> .build()  
> But each time when Solace has scheduled HA failover&nbsp;my client fails to reconnect to the server again. Below you can find error messages that I have from error handler (it just prints error reason and message). Even if I do have reconnection settings I don’t see any attempts of reconnecting on client side after the failure. Any ideas how to resolve this issue?  
> 2022-03-23 08:00:05,423 ERROR [error\_handlers.py:on\_reconnecting():48] - Error on\_reconnecting  
> 2022-03-23 08:00:05,424 ERROR [error\_handlers.py:on\_reconnecting():49] - Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Ok’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_COMMUNICATION\_ERROR’, ‘error\_info\_sub\_code’: 14, ‘error\_info\_contents’: ‘TCP: Could not read from socket 13, error = Connection reset by peer (104)’}  
> 2022-03-23 08:00:05,424 ERROR [error\_handlers.py:on\_reconnecting():50] - Message: TCP: Could not read from socket 13, error = Connection reset by peer (104)  
> 2022-03-23 08:00:09,699 ERROR [error\_handlers.py:on\_reconnecting():48] - Error on\_reconnecting  
> 2022-03-23 08:00:09,699 ERROR [error\_handlers.py:on\_reconnecting():49] - Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Ok’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_COMMUNICATION\_ERROR’, ‘error\_info\_sub\_code’: 14, ‘error\_info\_contents’: ‘TCP: Could not read from socket 14, error = Connection reset by peer (104)’}  
> 2022-03-23 08:00:09,699 ERROR [error\_handlers.py:on\_reconnecting():50] - Message: TCP: Could not read from socket 14, error = Connection reset by peer (104)  
> 2022-03-23 08:00:10,082 ERROR [error\_handlers.py:on\_service\_interrupted():53] - Error on\_service\_interrupted  
> 2022-03-23 08:00:10,082 ERROR [error\_handlers.py:on\_service\_interrupted():54] - Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Unknown (503)’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_SERVICE\_UNAVAILABLE’, ‘error\_info\_sub\_code’: 115, ‘error\_info\_contents’: ‘Service Unavailable’}  
> 2022-03-23 08:00:10,082 ERROR [error\_handlers.py:on\_service\_interrupted():55] - Message: Service Unavailable  
> 2022-03-23 08:00:13,091 ERROR [error\_handlers.py:on\_service\_interrupted():53] - Error on\_service\_interrupted  
> 2022-03-23 08:00:13,091 ERROR [error\_handlers.py:on\_service\_interrupted():54] - Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Unknown (503)’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_SERVICE\_UNAVAILABLE’, ‘error\_info\_sub\_code’: 115, ‘error\_info\_contents’: ‘Service Unavailable’}  
> 2022-03-23 08:00:13,091 ERROR [error\_handlers.py:on\_service\_interrupted():55] - Message: Service Unavailable

Thanks,  
Sergiy

---

<div class="post-metadata">

**Author:** ![AlexanderJHall](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@AlexanderJHall](https://community.solace.com/u/AlexanderJHall)\
**Post date:** [October 24, 2022, 9:58am UTC](https://community.solace.com/t/python-client-reconnection-failure/1196/2 "2022-10-24T09:58:00Z")

</div>

Hi,

> I also have a similar issue - every time we flip to HA our python client gets disconnected and fails to reconnect. We attempt to reconnect every 3 seconds for 5 minutes using a RetryStrategy.parameterized\_retry, but to no avail.  
> on\_reconnecting. Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Ok’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_COMMUNICATION\_ERROR’, ‘error\_info\_sub\_code’: 14, ‘error\_info\_contents’: ‘TCP: Could not read from socket 15, error = Connection reset by peer (104)’} Message: TCP: Could not read from socket 15, error = Connection reset by peer (104)  
> 2022-10-15 07:00:04.908 INFO:  
> on\_reconnecting. Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Ok’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_COMMUNICATION\_ERROR’, ‘error\_info\_sub\_code’: 14, ‘error\_info\_contents’: ‘TCP: Could not read from socket 13, error = Connection reset by peer (104)’} Message: TCP: Could not read from socket 13, error = Connection reset by peer (104)  
> RETURNING losrttp {t1}losrttp|1665176523219|1665666481128|Peq1IUXQXpyyGxx9ItM4wnQe4uU= None  
> 2022-10-15 07:05:08,409 [WARNING] solace.messaging.receiver: [\_message\_receiver.py:270]&nbsp;[[SERVICE: 0x7fb905cdab30] [RECEIVER: 0x7fb9064264a8]] Unable to Receive message. Messaging service disconnected.  
> 2022-10-15 07:05:08.409 INFO:  
> on\_service\_interrupted. Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Unknown (401)’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_LOGIN\_FAILURE’, ‘error\_info\_sub\_code’: 19, ‘error\_info\_contents’: ‘Unauthorized’} Message: Unauthorized  
> 2022-10-15 07:05:08.409 INFO: SolaceQueueReaderSource-id(140432642918048)thread(140434170173248) raised exception Unable to Receive message. Messaging service disconnected.  
> 2022-10-15 07:05:08.409 INFO: \_complete\_run raised exception. Exception was Unable to Receive message. Messaging service disconnected.  
> Traceback (most recent call last):  
> snip  
> snip  
> &nbsp;File “/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/solace/messaging/receiver/\_impl/\_message\_receiver.py”, line 272, in \_is\_message\_service\_connected  
> &nbsp;&nbsp;&nbsp;raise IllegalStateError(UNABLE\_TO\_RECEIVE\_MESSAGE\_MESSAGE\_SERVICE\_NOT\_CONNECTED)  
> solace.messaging.errors.pubsubplus\_client\_error.IllegalStateError: Unable to Receive message. Messaging service disconnected.  
> 2022-10-15 07:05:08.710 INFO:  
> on\_service\_interrupted. Error cause: {‘caller\_description’: ‘From service event callback’, ‘return\_code’: ‘Unknown (401)’, ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_LOGIN\_FAILURE’, ‘error\_info\_sub\_code’: 19, ‘error\_info\_contents’: ‘Unauthorized’} Message: Unauthorized

The code to build the connection is below.

> from solace.messaging.config.retry\_strategy import RetryStrategy  
> from solace.messaging.messaging\_service import MessagingService  
> \_KEEP\_TRYING\_TO\_CONNECT\_FOR\_NO\_MORE\_THAN\_MINUTES = 5
> 
> # 5 Minutes should be enough to ride out a badly timed reboot of the solace server.
> 
> \_INTERVAL\_BETWEEN\_CONNECTION\_ATTEMPTS\_MS = 3000  
> \_MAX\_CONNECTION\_ATTEMPTS = int(  
> &nbsp;&nbsp;&nbsp;\_KEEP\_TRYING\_TO\_CONNECT\_FOR\_NO\_MORE\_THAN\_MINUTES \* 60 / (\_INTERVAL\_BETWEEN\_CONNECTION\_ATTEMPTS\_MS / 1000)  
> )
> 
> # We try to reconnect for 5 minutes, every 3000 Milliseconds so max connection attempts is 5 \* 60 / (3000/1000) = 100
> 
> \_DEFAULT\_RECONNECT\_STRATEGY = RetryStrategy.parametrized\_retry(\_MAX\_CONNECTION\_ATTEMPTS,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_INTERVAL\_BETWEEN\_CONNECTION\_ATTEMPTS\_MS)  
> \_DEFAULT\_CONNECT\_STRATEGY = RetryStrategy.parametrized\_retry(\_MAX\_CONNECTION\_ATTEMPTS,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_INTERVAL\_BETWEEN\_CONNECTION\_ATTEMPTS\_MS)
> 
> class SolaceMessagingService:
> 
> def **init** (self,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;broker\_props: Dict,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service\_event\_handler=ServiceEventHandler(),  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection\_retry\_strategy: Optional[‘RetryStrategy’] = None,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reconnection\_retry\_strategy: Optional[‘RetryStrategy’] = None):
> 
> # Note: The reconnections strategy could also be configured using the broker properties object  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.messaging\_service = MessagingService.builder().from\_properties(broker\_props)   
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.with\_reconnection\_retry\_strategy(reconnection\_retry\_strategy or \_DEFAULT\_RECONNECT\_STRATEGY)   
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.with\_connection\_retry\_strategy(connection\_retry\_strategy or \_DEFAULT\_CONNECT\_STRATEGY)   
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build()

It would be wonderful to hear back with any suggestions!

---

<div class="post-metadata">

**Author:** ![sergkr21](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sergkr21](https://community.solace.com/u/sergkr21)\
**Post date:** [October 24, 2022, 2:29pm UTC](https://community.solace.com/t/python-client-reconnection-failure/1196/3 "2022-10-24T14:29:22Z")

</div>

> Hi,  
> In my case I resolved this issue using reconnection parameters 20 and 3000 and default connection strategy:  
> messaging\_service = MessagingService.builder().from\_properties(broker\_props)…with\_reconnection\_retry\_strategy(RetryStrategy.parametrized\_retry(20, 3000)).build()  
> But this is what is recommended in the best practice guide:

4.4. High Availability Failover and Reconnect Retries 4.4&nbsp;Reconnect duration should be set to at least 300 seconds when designing applications for High Availability (HA) support. All APIs When using High Availability (HA) redundant Solace router setup, a failover from one Solace router to its mate will typically occur within 30 seconds. However, an application should attempt to reconnect for at least for five minutes. Below is an example of setting the reconnect duration to five minutes using the following session property values: •&nbsp;Connect retries = 1 •&nbsp;Reconnect retries = 5 •&nbsp;Reconnect retry wait = 3000ms •&nbsp;Connect retries per host = 20  
You can find all these properties here:  
solace.messaging.config.solace\_properties.transport\_layer\_properties  
and configure them as part of broker\_props.

---

<div class="post-metadata">

**Author:** ![Tamimi](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/tamimi/32/2190_2.png) [@Tamimi](https://community.solace.com/u/Tamimi)\
**Post date:** [October 25, 2022, 3:43pm UTC](https://community.solace.com/t/python-client-reconnection-failure/1196/4 "2022-10-25T15:43:16Z")

</div>

Hey @sergkr21 and @AlexanderJHall thanks for raising this concern. We have alot of fixes coming up in v1.4.0 of the API so stay tuned. Some of the issues we saw was around hanging and deadlocks which might be different from your interruption issues, so can you please raise a ticket with support containing the details of your issue and sending to to [support@solace.com](mailto:support@solace.com) so we can track it for the next release if it was not already fixed. Thanks for raising issues you face!

---

<div class="post-metadata">

**Author:** ![cl0udf0x](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@cl0udf0x](https://community.solace.com/u/cl0udf0x)\
**Post date:** [January 22, 2025, 2:32am UTC](https://community.solace.com/t/python-client-reconnection-failure/1196/5 "2025-01-22T02:32:05Z")

</div>

@sergkr21 Thanks for the suggestion, this worked:

`messaging_service = ( MessagingService.builder() .from_properties(broker_props) .with_reconnection_retry_strategy(RetryStrategy.parametrized_retry(20, 3000)) .build()`

For completeness, using the `broker_props` didn’t work:  
`"solace.messaging.transport.reconnect-retries": 10, # Number of reconnection attempts "solace.messaging.transport.reconnect-retry-wait-time": 5000, # Time to wait between reconnection attempts (in milliseconds) "solace.messaging.transport.reconnect-retry-wait-time-increment": 2000, # Incremental wait time between reconnection attempts (in milliseconds) "solace.messaging.transport.reconnect-retry-wait-time-max": 30000, # Maximum wait time between reconnection attempts (in milliseconds)`  
Hi @Tamimi ,

Here are the packages in use if it’s any help.  
Thanks.  
`pip freeze |grep solace solace==0.1.22 solace-pubsubplus==1.9.0`
