EastEriq / LAST_Messaging

Messaging framework for the LAST project
0 stars 0 forks source link

spawning slaves with `.RemoteTerminal='none'` doesn't work anymore #3

Closed EastEriq closed 3 months ago

EastEriq commented 7 months ago

I suspect I have messed up something when merging with multimessenger.

One way of testing:

Unit=obs.unitCS('03');
Unit.Mount=inst.XerxesSimulated('03_1');
for i=1:2;Unit.Slave{i}.Logging=true; end
for i=1:2;Unit.Slave{i}.LoggingDir='/tmp'; end
Unit.Slave{1}.RemoteTerminal='none'; % or the other, or both
Unit.connectSlave(1:2)

I get misformed MasterMessenger or messages, e.g.

{Error using icinterface/fwrite (line 187)
Invalid network address.

Error in obs.util.MessengerCommon/reply (line 13)
    fwrite(Msng.StreamResource,flat);

Error in obs.util.Messenger/datagramParser (line 106)
           Msng.reply(jsonencode(ME.message)); % double quotes for json

Error in obs.util.Messenger>@(varargin)Msng.datagramParser(varargin{:}) (line 17)
                Msng.StreamResource.DatagramReceivedFcn=@Msng.datagramParser;

Error in instrcb (line 42)
        feval(val{1}, obj, eventStruct, val{2:end});
}
>> MasterMessenger.StreamResource.RemoteHost

ans =

    'AstroPack'
EastEriq commented 7 months ago

On [~,localhostname]=system('hostname -I') input can get dirty - why? Same pipe used? E.g.

>> [~,localhostname]=system('hostname -I')

localhostname =

    '{obs.util.Messenger} received '{"ReplyTo":{"Host":"{obs.util.Messenger}","Port":41238},"SentTimestamp":739286.6024139045,"ReceivedTimestamp":[],"ProgressiveNumber":9,"Command":"feature('getpid')","RequestReply":true,"Content":[],"EvalInListener":false}' from 127.0.0.1:41238 on 04-Feb-2024 14:27:28
     {obs.util.Messenger} could not change DestinationHost. Maybe connection is open?
     {obs.util.Messenger} problem sending the json encoded result of command "feature('getpid')"
     Error using icinterface/fwrite (line 187)
     Invalid network address.

     Error in obs.util.MessengerCommon/reply (line 13)
         fwrite(Msng.StreamResource,flat);

     Error in obs.util.Messenger/datagramParser (line 106)
                Msng.reply(jsonencode(ME.message)); % double quotes for json

     Error in obs.util.Messenger>@(varargin)Msng.datagramParser(varargin{:}) (line 17)
                     Msng.StreamResource.DatagramReceivedFcn=@Msng.datagramParser;

     Error in instrcb (line 42)
             feval(val{1}, obj, eventStruct, val{2:end});

     10.23.3.5 
     '

Then at line 29 og obs.util.MessengerCommon.send M.ReplyTo.Host becomes {obs.util.Messenger}, which can't be set to Msng.StreamResource.RemoteHost, etc.

EastEriq commented 3 months ago

As of now the status is "yes, it does work again". However, the lesson learned is that one has to be very cautious when using system() commands -- it seems that system() works piping stdout, and if matlab concomitantly writes on stdout (fprintf, .report, or just matlab shell's own output), funny text can sneak into what system() reads. Notably (or perhaps only?) for slaves run headless. It is not completely clear to me what goes about stdout, whether logging to file is on or off. One mitigation to the problem may be to try to purge stdout with a [~,r]=system(''); before any sensible command, another one to parse the result string keeping only the last line of output, and so I did in the code -- but all toghether that is not the ultimate solution.