Socket connection ignored in Virtual Serial Datasource after disconnect
-
Hi Phil, figured this would likely be your domain.
Have been implementing a TCP socket connector in C#.net.
I set up a virtual serial port server in mango, no read timeout, low buffer of 100 and my required listening port.
The good news is it connects, I can see in the datasource logs the data coming in. However, should I get disconnected or actually close the connection then reconnect, I can no longer get data going into the datasource, nor can I send anything out of the datasource on one of it's datapoints back to my program.Looking into the datasource log, it's almost as if the data is trapped and the serial data source does a closed loop on itself. data leaves the datasource then comes back in again. It never actually leaves my interface.
The only way to get two way communication resolved again is restarting the datasource then reconnecting with the Socket connector. Which makes me believe the virtual datasource adaptor needs to remove the binding for the client end local port number should there be a disconnect or at least a connection timeout is needed....
Your thoughts?Fox
-
Hi Fox,
Anyone is welcome to my domain! I'm just also here....
It is possible there are unresolved issues in the serial server socket, but I was not able to clearly reproduce. My test is this configuration:
{ "dataSources":[ { "xid":"DS_ef61c883-191d-43af-95a3-d4d0f61c46b6", "name":"Serial", "enabled":true, "type":"SERIAL", "alarmLevels":{ "POINT_READ_PATTERN_MISMATCH_EVENT":"URGENT", "POINT_WRITE_EXCEPTION":"URGENT", "DATA_SOURCE_EXCEPTION":"URGENT", "POINT_READ_EXCEPTION":"URGENT" }, "purgeType":"YEARS", "baudRate":115200, "commPortId":"COMMO", "dataBits":8, "flowControlIn":0, "flowControlOut":0, "hex":false, "ioLogFileSizeMBytes":1.0, "logIO":true, "maxHistoricalIOLogs":1, "maxMessageSize":1024, "messageRegex":"().*", "messageTerminator":";", "parity":0, "pointIdentifierIndex":1, "readTimeout":1000, "retries":1, "stopBits":1, "useTerminator":false, "editPermission":"", "purgeOverride":false, "purgePeriod":1 } ], "dataPoints":[ { "xid":"DP_fb5749cc-5b0d-4345-a8a7-0c7686ab8e9c", "name":"Catchall", "enabled":true, "loggingType":"ON_CHANGE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"INSTANT", "purgeType":"YEARS", "pointLocator":{ "dataType":"ALPHANUMERIC", "pointIdentifier":"", "valueIndex":0, "valueRegex":"(?:.|\\r|\\n)+" }, "eventDetectors":[ ], "plotType":"STEP", "rollup":"NONE", "unit":"", "templateXid":"Alphanumeric_Default", "chartColour":"", "chartRenderer":{ "type":"TABLE", "limit":10 }, "dataSourceXid":"DS_ef61c883-191d-43af-95a3-d4d0f61c46b6", "defaultCacheSize":1, "deviceName":"Serial", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":15, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"PLAIN", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "suffix":"" }, "tolerance":0.0 } ], "virtualSerialPorts":[ { "type":"SERIAL_SERVER_SOCKET_BRIDGE", "bufferSize":4, "port":1620, "timeout":0, "portName":"COMMO", "xid":"VSP_640ff0e9-4e88-4129-8802-b10633cec732" } ] }
The other end of the connection was a simple
nc localhost 1620
. I tested both staying connected and breaking the connection each time.I did notice I got it in a state where the data point would appear to update but would have an empty value! Checking its history revealed it had two values at that time, one was the value I expected and one was a blank message. I resolved that issue by changing my point's regex from
(?:.|\r|\n)*
to(?:.|\r|\n)+
You can see the buffer size is very small for the serial server socket bridge but it still worked for larger messages in my test, so long as they are smaller than the data source's maximum size.
Does that seem familiar? Might your point also be resetting to a blank value, but actually have the expected values in history?
-
My suspicion is that because the buffer size at the virtual socket is small, it is sending multiple serial events which is creating two timers to process the data source's buffer. This is fine as they are synchronized, but the second invocation produces the blank value. I committed this fix:
https://github.com/infiniteautomation/ma-modules-public/commit/1b86b635b27c30e36e30b40e3e049ba016c9e3fbYou may need to have a larger default cache size (or viewing the last 10 values including cached values such that the points cache expands) to see the real samples because they may be overwritten by blank values at the same millisecond.
-
Thanks for testing Phil!
Just wanted to ask, how do I apply that fix? Don't want to bring anything down when I apply the change....
As for the blank value, yes I was certainly getting those when I was connecting fine, though i guess the blank was to do with my regex.
I'll use your datasource and point as a testing baseline and will fire random text to it.@phildunlap said in Socket connection ignored in Virtual Serial Datasource after disconnect:
Does that seem familiar? Might your point also be resetting to a blank value, but actually have the expected values in history?
I did wonder that, but when I was using tail -f on the datasource log file I wasn't seeing anything coming in - even though my socket was connected!
I'll log my findings and will come back to you with some more viable data to work with. I used tcpdump on my server to check incoming and outgoing - i'll log that for you as well as a wireshark log if that is any use to you too. -
Just wanted to ask, how do I apply that fix? Don't want to bring anything down when I apply the change....
Alas it won't be released until 3.4 probably. But, you shouldn't really need it. It only prevents the extra empty serial events, but those shouldn't really cause problems.
I'll use your datasource and point as a testing baseline and will fire random text to it.
Great! Let us know how it goes!