sending data concurrently to multiple streams for pattern may lead to deadlock
Allan-QLB opened this issue · comments
Description:
sending data concurrently for pattern may lead to deadlock
Affected Siddhi Version:
5.x.x
OS, DB, other environment details and versions:
N/A
Steps to reproduce:
The cause is as follow
Thread1:
- ProcessStreamReceiver#process
- lock the "lockWrapper"
- SingleProcessStreamReceiver#processAndClear
- synchronize "patternSyncObject"
Thread2:
- MultiProcessStreamReceiver#receive
- synchronize "patternSyncObject"
- MultiProcessStreamReceiver#process
- lock "lockWrapper"
the deadlock occur when Thread1,Thread2 are both between step 2 and step 4
It's easy to reproduce , just sleep for a while before synchronizing "patternSyncObject" in SingleProcessStreamReceiver#processAndClear,
then send data in different threads
script is like this:
@App:name('Test')
define stream RegulatorStateChangeStream(time long, deviceID long,
roomNo int, tempSet double, action string);
define stream RoomKeyStream(time long, deviceID long, roomNo int,
action string);
@sink(type='log')
define stream RegulatorActionStream(time long, roomNo int, action string);
from every (e1=RegulatorStateChangeStream[ action == 'on' ]
-> e2=RoomKeyStream
[ e1.roomNo == roomNo and action == 'removed' ]
or e3=RegulatorStateChangeStream
[ e1.roomNo == roomNo and action == 'off'])
select eventTimestamp() as time, e1.roomNo,
ifThenElse( e2 is null, 'none', 'stop' ) as action
having action != 'none'
insert into RegulatorActionStream;`
the deadlock occur when sending data to RegulatorStateChangeStream
and RoomKeyStream
in different thread