-
Notifications
You must be signed in to change notification settings - Fork 32
Description
The retry loop in concore_read.m has two problems that'll bite you in any real MATLAB study:
- No error handling inside the retry loop
The first read attempt is wrapped in try-catch, which is fine. But the while loop that retries on empty content has bare fopen/fscanf/fclose calls with no protection:
while length(ins) == 0
pause(concore.delay);
input1 = fopen(strcat(concore.inpath,num2str(port),'/',name));
ins = fscanf(input1,'%c');
fclose(input1);
concore.retrycount = concore.retrycount + 1;
end
If fopen fails here (returns -1), fscanf(-1, ...) throws an error and the whole function dies. The Python equivalent in both concore.py and concoredocker.py wraps retries in try-except — MATLAB should do the same.
- No max retry limit
The Python implementations cap retries at 5 (max_retries = 5). The MATLAB loop just goes while length(ins) == 0 with no upper bound. If the writing node crashes or the file stays empty for any reason, this spins forever and the study hangs with no feedback.
Both issues together mean that if anything goes wrong during a MATLAB node's read, you either get an unhandled crash or an infinite hang — neither gives you anything useful to debug.
Fix can be, wrap the loop body in try-catch (same as the initial read), add a max retry counter, and print a message when retries are exhausted so the user knows what happened.