question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to recover from socket error 10054 (Modbus TCP)?

See original GitHub issue

Hello all,

I am testing the Modbus functionality using an Advantech WISE-4060/LAN module. I am reading 3 coils at a 1 second interval. The communication drops and I noticed ErrorBusy exception messages in the logging of my test application. My initial test application used libplctag but I was unable to get more logging than ErrorBusy. Then I rewrote the test application to use libplctag.NativeImport and this provided more logging:

[current iteration: 731, current handle: 0]: 0
2021-09-16 11:48:37.504 thread(1) tag(12) INFO plc_tag_read:1131 Starting.
2021-09-16 11:48:37.504 thread(1) tag(12) DETAIL mb_read_start:1746 Starting.
2021-09-16 11:48:37.504 thread(1) tag(12) DETAIL mb_read_start:1769 Done.
2021-09-16 11:48:37.518 thread(3) tag(12) INFO create_read_request:1205 Starting.
2021-09-16 11:48:37.519 thread(3) tag(12) DETAIL create_read_request:1207 seq_id=2198
2021-09-16 11:48:37.519 thread(3) tag(12) DETAIL create_read_request:1208 registers_per_request = 2000
2021-09-16 11:48:37.520 thread(3) tag(12) DETAIL create_read_request:1209 base_register = 2
2021-09-16 11:48:37.520 thread(3) tag(12) DETAIL create_read_request:1210 register_count = 1
2021-09-16 11:48:37.520 thread(3) tag(12) INFO create_read_request:1217 preparing read request for 1 registers (of 1 total) from base register 2.
2021-09-16 11:48:37.521 thread(3) tag(12) DETAIL create_read_request:1294 Done.
2021-09-16 11:48:37.533 thread(3) tag(0) DETAIL write_packet:978 Full packet written.
2021-09-16 11:48:37.535 thread(3) tag(0) DETAIL write_packet:979  08 96 00 00 00 06 00 01 00 02
2021-09-16 11:48:37.535 thread(3) tag(0) DETAIL write_packet:979  00 01
2021-09-16 11:48:37.548 thread(3) tag(0) DETAIL read_packet:892 data_needed=4, packet_size=4, read_data_len=6
2021-09-16 11:48:37.549 thread(3) tag(0) DETAIL read_packet:892 data_needed=0, packet_size=4, read_data_len=10
2021-09-16 11:48:37.549 thread(3) tag(0) DETAIL read_packet:917 Received full packet.
2021-09-16 11:48:37.549 thread(3) tag(0) DETAIL read_packet:918  08 96 00 00 00 04 00 01 01 00
2021-09-16 11:48:37.549 thread(3) tag(12) INFO check_read_response:1120 Starting.
2021-09-16 11:48:37.549 thread(3) tag(12) INFO check_read_response:1137 Got read response 2198 of length 10 with payload of size 1.
2021-09-16 11:48:37.550 thread(3) tag(12) DETAIL check_read_response:1138 registers_per_request = 2000
2021-09-16 11:48:37.550 thread(3) tag(12) DETAIL check_read_response:1139 register_offset = 0
2021-09-16 11:48:37.550 thread(3) tag(12) DETAIL check_read_response:1140 byte_offset = 0
2021-09-16 11:48:37.550 thread(3) tag(12) DETAIL check_read_response:1141 copy_size = 1
2021-09-16 11:48:37.551 thread(3) tag(12) DETAIL check_read_response:1152 Read is complete.
2021-09-16 11:48:37.551 thread(3) tag(12) DETAIL check_read_response:1191 Done.
2021-09-16 11:48:37.563 thread(1) tag(12) INFO plc_tag_read:1246 elapsed time 58ms
2021-09-16 11:48:37.565 thread(1) tag(12) INFO plc_tag_read:1264 Done
[current iteration: 731, current handle: 1]: 0
2021-09-16 11:48:37.565 thread(1) tag(13) INFO plc_tag_read:1131 Starting.
2021-09-16 11:48:37.565 thread(1) tag(13) DETAIL mb_read_start:1746 Starting.
2021-09-16 11:48:37.565 thread(1) tag(13) DETAIL mb_read_start:1769 Done.
2021-09-16 11:48:37.579 thread(3) tag(13) INFO create_read_request:1205 Starting.
2021-09-16 11:48:37.580 thread(3) tag(13) DETAIL create_read_request:1207 seq_id=2199
2021-09-16 11:48:37.580 thread(3) tag(13) DETAIL create_read_request:1208 registers_per_request = 2000
2021-09-16 11:48:37.581 thread(3) tag(13) DETAIL create_read_request:1209 base_register = 3
2021-09-16 11:48:37.581 thread(3) tag(13) DETAIL create_read_request:1210 register_count = 1
2021-09-16 11:48:37.581 thread(3) tag(13) INFO create_read_request:1217 preparing read request for 1 registers (of 1 total) from base register 3.
2021-09-16 11:48:37.581 thread(3) tag(13) DETAIL create_read_request:1294 Done.
2021-09-16 11:48:37.594 thread(3) tag(0) DETAIL write_packet:978 Full packet written.
2021-09-16 11:48:37.596 thread(3) tag(0) DETAIL write_packet:979  08 97 00 00 00 06 00 01 00 03
2021-09-16 11:48:37.596 thread(3) tag(0) DETAIL write_packet:979  00 01
2021-09-16 11:48:37.609 thread(3) tag(0) DETAIL read_packet:892 data_needed=4, packet_size=4, read_data_len=6
2021-09-16 11:48:37.610 thread(3) tag(0) DETAIL read_packet:892 data_needed=0, packet_size=4, read_data_len=10
2021-09-16 11:48:37.610 thread(3) tag(0) DETAIL read_packet:917 Received full packet.
2021-09-16 11:48:37.610 thread(3) tag(0) DETAIL read_packet:918  08 97 00 00 00 04 00 01 01 00
2021-09-16 11:48:37.610 thread(3) tag(13) INFO check_read_response:1120 Starting.
2021-09-16 11:48:37.611 thread(3) tag(13) INFO check_read_response:1137 Got read response 2199 of length 10 with payload of size 1.
2021-09-16 11:48:37.611 thread(3) tag(13) DETAIL check_read_response:1138 registers_per_request = 2000
2021-09-16 11:48:37.611 thread(3) tag(13) DETAIL check_read_response:1139 register_offset = 0
2021-09-16 11:48:37.611 thread(3) tag(13) DETAIL check_read_response:1140 byte_offset = 0
2021-09-16 11:48:37.612 thread(3) tag(13) DETAIL check_read_response:1141 copy_size = 1
2021-09-16 11:48:37.612 thread(3) tag(13) DETAIL check_read_response:1152 Read is complete.
2021-09-16 11:48:37.612 thread(3) tag(13) DETAIL check_read_response:1191 Done.
2021-09-16 11:48:37.624 thread(1) tag(13) INFO plc_tag_read:1246 elapsed time 59ms
2021-09-16 11:48:37.627 thread(1) tag(13) INFO plc_tag_read:1264 Done
[current iteration: 731, current handle: 2]: 0
2021-09-16 11:48:38.642 thread(1) tag(11) INFO plc_tag_read:1131 Starting.
2021-09-16 11:48:38.642 thread(1) tag(11) DETAIL mb_read_start:1746 Starting.
2021-09-16 11:48:38.643 thread(1) tag(11) DETAIL mb_read_start:1769 Done.
2021-09-16 11:48:38.658 thread(3) tag(11) INFO create_read_request:1205 Starting.
2021-09-16 11:48:38.658 thread(3) tag(11) DETAIL create_read_request:1207 seq_id=2200
2021-09-16 11:48:38.659 thread(3) tag(11) DETAIL create_read_request:1208 registers_per_request = 2000
2021-09-16 11:48:38.659 thread(3) tag(11) DETAIL create_read_request:1209 base_register = 1
2021-09-16 11:48:38.660 thread(3) tag(11) DETAIL create_read_request:1210 register_count = 1
2021-09-16 11:48:38.660 thread(3) tag(11) INFO create_read_request:1217 preparing read request for 1 registers (of 1 total) from base register 1.
2021-09-16 11:48:38.660 thread(3) tag(11) DETAIL create_read_request:1294 Done.
2021-09-16 11:48:38.674 thread(3) tag(0) DETAIL write_packet:978 Full packet written.
2021-09-16 11:48:38.676 thread(3) tag(0) DETAIL write_packet:979  08 98 00 00 00 06 00 01 00 01
2021-09-16 11:48:38.676 thread(3) tag(0) DETAIL write_packet:979  00 01
2021-09-16 11:48:38.800 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 11:48:38.800 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!
2021-09-16 11:48:39.647 thread(1) tag(11) WARN plc_tag_read:1236 Read operation timed out.
2021-09-16 11:48:39.647 thread(1) tag(11) INFO plc_tag_read:1246 elapsed time 1004ms
2021-09-16 11:48:39.648 thread(1) tag(11) INFO plc_tag_read:1264 Done
2021-09-16 11:48:43.814 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 11:48:43.814 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!

<<< This goes on and on because of the client application, plc_tag_status returns 1 >>>

2021-09-16 13:10:07.090 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 13:10:07.090 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!

<<< Using the debugger to step over to the next tag. >>>

Something went wrong 1
[current iteration: 732, current handle: 0]: 0
2021-09-16 13:10:11.906 thread(1) tag(12) INFO plc_tag_read:1131 Starting.
2021-09-16 13:10:11.906 thread(1) tag(12) DETAIL mb_read_start:1746 Starting.
2021-09-16 13:10:11.907 thread(1) tag(12) DETAIL mb_read_start:1769 Done.
2021-09-16 13:10:12.098 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 13:10:12.098 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!
2021-09-16 13:10:12.910 thread(1) tag(12) WARN plc_tag_read:1236 Read operation timed out.
2021-09-16 13:10:12.910 thread(1) tag(12) INFO plc_tag_read:1246 elapsed time 1003ms
2021-09-16 13:10:12.911 thread(1) tag(12) INFO plc_tag_read:1264 Done
2021-09-16 13:10:17.105 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 13:10:17.105 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!

Something went wrong 1

<<< Using the debugger to step over to the last tag. >>>

[current iteration: 732, current handle: 1]: 0
2021-09-16 13:10:46.399 thread(1) tag(13) INFO plc_tag_read:1131 Starting.
2021-09-16 13:10:46.399 thread(1) tag(13) DETAIL mb_read_start:1746 Starting.
2021-09-16 13:10:46.399 thread(1) tag(13) DETAIL mb_read_start:1769 Done.
2021-09-16 13:10:47.163 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 13:10:47.163 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!
2021-09-16 13:10:47.400 thread(1) tag(13) WARN plc_tag_read:1236 Read operation timed out.
2021-09-16 13:10:47.400 thread(1) tag(13) INFO plc_tag_read:1246 elapsed time 1000ms
2021-09-16 13:10:47.401 thread(1) tag(13) INFO plc_tag_read:1264 Done
2021-09-16 13:10:52.169 thread(3) tag(0) WARN socket_read:1229 socket read error rc=-1, errno=10054
2021-09-16 13:10:52.169 thread(3) tag(0) WARN read_packet:909 Error, PLCTAG_ERR_READ, reading socket!

<<< And so on >>>

The code I am using is similar to the code provided at: https://github.com/libplctag/libplctag.NET/blob/master/src/Examples/CSharp NativeImport/NativeImportExample.cs and my connection string reads: “protocol=modbus_tcp&gateway=10.0.0.1:502=&path=0&elem_count=1&name=co1&debug=4”

Is this expected behaviour and should I recover from it by disposing the tags (libplctag) or destroying the tags (libplctag.NativeImport) or is there something else I can do to recover from this.

As a side node, I am using libplctag also with an Allen Bradley ControlLogix and I have not experienced issues like this with the Allen Bradley.

I tested this on versions:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:25 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
fmartenscommented, Oct 15, 2021

@timyhac , it seems you already added the 2.4.0 libplctag libraries to the native export which contains the fix. I will retest the official nuget (and remove my Frankenstein solution) and close this issue.

Thanks for taking care.

0reactions
fmartenscommented, Oct 17, 2021

I updated the NuGet and ran a test. It did not fail and it did not had to reconnect. The NuGet includes the libplctag library that fixes the issue so I’ll close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct socket communications error 10054
We are running Lookout 5.1 (build reading data through Modbus Ethernet Drivers and we are constantly getting "socket communications error ...
Read more >
Socket Error 10054, Connection reset by peer
1] Check Peer to Peer connection · 2] Disable your firewall · 3] Reset TCP/IP and flush the DNS cache · 4] Modify...
Read more >
Common Causes of Socket Error 10054 and How to Fix
The socket error 10054 is caused by an existing connection that is. ... In the Command Prompt, type netsh winsock reset and press...
Read more >
Python socket error 10054, connection was interrupted by ...
1 Answer 1 ... You must close the sockets that you opened otherwise they will be open until a timeout reached. Try this:...
Read more >
Windows Sockets error 10054
1. Check Peer to Peer connection ... According to Microsoft, the Windows Sockets error 10054 is a "connection reset by peer. An existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found