jmccrohan / pysolarmanv5

A python module to interact with Solarman Data Logging Sticks
MIT License
132 stars 28 forks source link

Thread Error (concurrency), Socket closed or lost #44

Closed jlopez77 closed 1 year ago

jlopez77 commented 1 year ago

Hi!

I'm using your integration to write an API for my Deye Inverter but I'm facing errors that force me to restart the API whenever the connection is not used for 3 to 10 minutes. I'm using the auto_reconnect option and sometimes it works but eventually, when a read or write operation is performed, the following error is thrown and cannot be recovered.

Exception in thread Thread-4: Traceback (most recent call last): File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/usr/local/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/home/pi/.local/lib/python3.8/site-packages/pysolarmanv5/pysolarmanv5.py", line 299, in _data_receiver data = self.sock.recv(1024) ConnectionResetError: [Errno 104] Connection reset by peer

githubDante commented 1 year ago

This is definitely a discrepancy between the sync and async versions. Connection reset is handled in the latter. A try/except block assigning empty bytes to the data variable on reset should fix it.

jlopez77 commented 1 year ago

That's what I ended up doing :)

githubDante commented 1 year ago

Thanks for the report. If @jmccrohan knows how to add you to the co-authors that would be great :)

jmccrohan commented 1 year ago

Thanks @jlopez77 and @githubDante. I've pushed b87f4a0 now which resolves this and #45.

Btw, you can add Co-authored-by: to commit messages to credit additional developers.