Zapit-Optostim / zapit

General purpose optostimulation system
GNU Lesser General Public License v2.1
6 stars 1 forks source link

sendSamples blocking behavior with finite samples causes the TCP/IP client to block also #135

Closed raacampbell closed 11 months ago

raacampbell commented 11 months ago

Problem

When the client calls TCPclient.sendSamples with a finite stimulus, it waits (is blocked) by zapit.pointer.sendSamples (on the server) to finish before it returns. This is a problem because it means the user can not then trigger a trial because the MATLAB session on the client is blocked. The reason this happens is because the client waits for a TCP/IP reply that can't be sent until zapit.pointer.sendSamples has finished.

Quick Fix

The fastest fix is to send back the response before zapit.pointer.sendSamples has run. We simply will not return the stimulus identity and laser state. This likely won't matter as it's only a concern if the user is expecting these values to be assigned manually by zapit.pointer.sendSamples and needs to know what they were on the client.

Quick Fix Followup

We can follow on from the above by feeding the last laser state and last condition number into a property that is read off by processBufferMessageCallback instead of waiting for sendSamples to complete. This is easy enough to do.

Ideal Solution

The big problem with the above is that the problem must extend to the local MATLAB session and so the above fix only helps if the user is on TCP/IP. Further, the solution does not stop the client from sending messages to the server even when the server is in a blocked state. The server will fail to respond and that too will block the client. This is unlikely to be a concern in practice but we could avoid all this mess by having zapit.pointer.sendSamples be non-blocking and instead have routines to check if a stimulus is currently being presented and, if not, to stop the DAQ task before setting up the next stimulus. This will need investigation so for now we proceed with the quicker fixses.

raacampbell commented 11 months ago

With a68ebd4cf299acb94911449b93f269de623f6ec0 we implement the Quick Fix. This commit is totally untested.

raacampbell commented 11 months ago

Above didn't work so revert it and work on the ideal solution 3af409ddd5c1407bea2e73085f2055e5ca563ed8 Here we do not block. We stop the task if a finite acq task already exists instead of connecting to the DAQ. We don't run sendSamples if finite samples are already being produced.

raacampbell commented 11 months ago

This works