Edge: client socket not returning timeout error

I have a driver that is using TCP client socket to send/receive data to a device. Sometimes the device doesn’t respond for whatever reason, and in those cases I expect the receive call to return a timeout error. But it doesn’t, even though there is a client socket timeout set, in this case, for 5 seconds. Instead, the receive call is returning nil for both the data and the error return values.

.
.
.
client:settimeout(5)
local line, err, partial = client:receive('*l')

In the case the device isn’t responding, the above call returns nil for all 3 return values. However according to the Lua socket documentation:

If successful, the method returns the received pattern. In case of error, the method returns nil followed by an error message which can be the string ‘closed’ in case the connection was closed before the transmission was completed or the string ‘timeout’ in case there was a timeout during the operation. Also, after the error message, the function returns the partial result of the transmission.

So there appears to be a bug in the cosock implementation that is failing to set the return error message in the case of timeouts.

For now I am just assuming a timeout when I see line and err both nil, but this should probably be fixed.

Thank you for bringing this to our attention. The team will review the configuration, I’ll let you know once I get more info. :wink:

1 Like