While starting a named shared Matlab engine in R2018b, I got the following error:
Error using matlab.engine.shareEngine (line 41)
MATLAB session 'MATLABEngineX' already exists. Current MATLAB session is now shared with default name 'MATLAB_5960'.
I am using this engine from python, who actually does not see the MATLABEngineX session, only the new MATLAB_5960. The former session was indeed not closed properly and apparently turned into a zombie session.
I did not find any question regarding this issue and it took me quite some time to find out how to solve it: there is a zero-byte file in C:\Temp with the name of the engine that apparently serves as a marker for Matlab (but not for python). Manually removing this file resolved the issue.
I don't understand why Matlab needs this marker if python does not, but it would be good to include a hint in the error message. For example:
MATLAB session 'MATLABEngineX' already exists (if this is due to a session not being closed properly, remove the file C:\Temp\MATLABEngineX).