LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP read does not generate error when connection is in "mode 58"

When a TCP connection is in "mode 58" (The network function is not supported by the system) which is like half closed or similar. If I try to write to that connection I get error 58, if I try to read from that connection I get no error and TCP read returns immediately what ever the mode or the timeout.

 

Why TCP write reports the error and TCP read does not?

 

The doc says "Standard (default)—Waits until all bytes you specify in bytes to read arrive or until timeout ms runs out. Returns the number of bytes read so far. If fewer bytes than the number of bytes you requested arrive, returns the partial number of bytes and reports a timeout error." same for the other modes.

 

The work around is to test if TCP read returns immediately (< 1ms) and that the number of bytes read is 0.

 

LabVIEWcommunity 2025Q3, OSX 26.6.2

0 Kudos
Message 1 of 5
(669 Views)

Never heard about mode 58. I think you mean error 58 but I never got that error and I would not really know why TCP Write would return error 58 ever. It sounds like the underlaying socket got stuck in the network disconnect state after the remote side tried to close the connection or your cable had some sort of (temporary) hiccup. Are you unplugging the cable? Is it a poor Wifi connection that sometimes breaks the connection briefly?

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 5
(621 Views)

Hi Rolf

 

"mode 58" was the best description I could find to describe the connection status (half closed?).

This code has been running for years, but lately I saw this new behaviour.

The servers are connected through Ethernet and are constantly "probed" from outside world in addition to valid connections. 

While TCP Write works as expected and returns an error, TCP read behaviour does not follow its specifications and additional workaround is need to handle this case.

 

Ch.

0 Kudos
Message 3 of 5
(578 Views)

I see.  When the socket driver detects anomalies it can invoke a connection reset which ultimately turns into a connection close. But there is some back and forth handshaking involved in that and the connection is not considered closed by the socket layer until both sides have send the final FIN message and received an ACK for it. It seems your socket is stuck in FIN_WAIT2 or maybe FIN-WAIT1 state for some reason.

 

The socket is considered dead for outgoing packets but still kept alive for incoming messages to possibly catch late arrivals that could result from dynamic routing of packets to circumvent damaged connection infrastructure. This is a feature of the TCP/IP protocol, not a bug.

 

There seems to be a bug that TCP Read in your case returns no error and no data despite you specifying to read more than 0 bytes? Or does some of your handling for some reason actually result in a TCP Read call with 0 bytes to read??? If you specify more than 0 bytes to TCP Read and get no error and no data that would be something to report to NI as bug as it is truly unexpected. TCP Read should either return with at least a byte or more (depending on the read mode) or cause a timeout error.

 

The rest however does not look like a LabVIEW error. Apparently the socket has started to behave differently than in the past for some reason. Possible reasons might be an OS update that changed something in the socket library to fix some potential security problem. Or in the network drivers itself, Intel and also Broadcom tend to update their drivers almost every month currently. A hardware failure is definitely also not impossible. The network chip starting to misbehave because of age or thermal problems but don't forget the cable either. Quite regularly they do get damaged in a way that they still seem to work but micro defects from strong bends or compression of the cable from anything having driven over them or stepped on them can cause irregularities that cause reflections in the cable that distort the high frequency components from modern network traffic.

 

What can you do on the LabVIEW side? Even if you report this bug and NI would somehow fix the "no timeout" error on the TCP Read in this situation, you would not be much further with your current app setup. Basically, LabVIEW network functions have one simple rule, any error returned from any of them indicates a serious error that should cause you to close that connection and reestablish a new connection with the exception of timeout errors (56) on TCP Read and TCP Listen. This would mean that on the Write side you detect the 58 error and as a consequence close the refnum.

 

It depends a bit on your setup but it would seem to me that you probably have a system where you separate the refnum and treat the read separately from the write somehow. Even then it would work since the TCP Read will return with error 1 when you close the refnum elsewhere. Of course you will have a problem in your current situation as you will need to reopen the socket after closing it and somehow relaying the new refnum to the other side. One quick and halfway decent solution is to put the refnum handling with "open", "close" and "get" into an Intelligent global variable, if you only need one such handler. If your setup requires multiple such handlers on multiple refnums you will have to redesign something.

 

The big basic rule about robust network connection handling is:

 

Any error other than a timeout error on Listen or Read indicates a real error that should result in a Close of that connection and reestablishing a new connection.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 5
(567 Views)

On a possibly tangential note, make sure your firewall defenses don't implement that stealth myth peddled by Steve Gibson in the early days of home networks.

 

Back in the days, I have strongly argued against it, but was always in the minority. I think that has changed in the las decade+ 😄

 

altenbach_0-1791041516557.png

 

For many years, I was actually beta testing several dozens home and corporate firewall appliances for a well known manufacturer and as a hobby, I even wrote a LabVIEW program that used the telnet protocol to log into the appliance to configure it to send all raw packet data on all interfaces to my program where I parsed the packet headers of many protocols natively in real-time. That was well before Wireshark came out. 😄 It even helped finding a bug in their FTP NAT implementation that caused a disconnect under very (very!) rare conditions. Having every single header bit of a long download was essential. Early implementations of the "Great firewall of China" could be defeated by just blocking RST packets that they injected into any undesired communication. Ahh, the good old wild west times of networking! 😄

 

Message 5 of 5
(551 Views)