Not so much crashes, but stalls. Each tag change event is given one dedicated thread to process all incoming events. If the script includes any code that sleeps, or waits for a condition, other events will pile up behind it.
When this happens, you should check the gateway script monitoring pages, and perhaps take a thread dump. This will help you find the stuck spot.
def __startServer__(listenPort,listenTimeout,recvBufferLen,tagPathBase):
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', listenPort))
server.listen(10)
system.tag.writeBlocking(["{}/dataRecv".format(tagPathBase)
,"{}/clientHasDisconnected".format(tagPathBase)], ['',False])
client_socket, addr = server.accept()
client_socket.settimeout(listenTimeout)
server.close()
system.tag.writeBlocking(["{}/startServer".format(tagPathBase)], [False])
bb=bytearray()
while True:
try:
chunk = client_socket.recv(recvBufferLen)
if not chunk:
print("Sensor disconnected")
system.tag.writeBlocking(["{}/clientHasDisconnected".format(tagPathBase)], [True])
break
bb.extend(chunk)
except socket.timeout:
if bb:
process_frame(tagPathBase,bb)
#buffer.clear()
del bb[:]
where __startServer__ is called by a system.util.invokeAsynchronous
That's the code: I don't think anything is wrong. I think that Tag Change script editor is doing something wrong in this 8.3.8 version: why should starting the script with an if clause be wrong, if indentation is correct? Never happened before. Moreover after restarting the gateway all is working correctly, no tag change event get missed. What's that "missing event subscriber for an annotated event"? Nothing to do with my script, I think
You are launching a long-lived thread with no tracking of it in a persistent way, and with no way to safely kill and replace it. This is recipe for leaking memory and blocking many threads indefinitely, all leading to gateway crashes/misbehavior. Some guidance:
The syntax error warning is a bug in the editor that's fixed in 8.3.9, but it's just a bug in the editor; actual script compilation and execution are unaffected, so it's not the root cause of whatever else is going on.