Concurrency issue accessing license file?

Hello,

we have a defined a visual plugin in a .NET assembly. The host application is developed in Delphi.
This VisualPlugin loads and works just fine, For several years already :slight_smile:

We recently added a new feature to our software. When this feature is activated, several instances of our delphi hydra host application are spawned simultaneously.

This is where we sporadically receive the following error (from unit uHYRes):

err_CannotInstantiateManagedPlugin = ‘Unable to instantiate managed plugin class “%s”. Most likely the type is not declared as “public”, type or assembly are marked as ComVisible(false), or missing/incorrect license file is detected.’;

The error is raised in the function uHYManagedSupport.CreateManagedPluginInstance.

The type is public and marked as ComVisible. Otherwise it would never work.
So the problem must be related with the license file.

The licence file is also obviously valid, otherwise trying to instantiate the visual plugin would always fail.

My guess is that the problem might be concurrent access to the license file. We have several delphi hosts trying to acess the license file at the ‘same’ time, so I guess that the file is locked while being read, which would then cause any other attempt to read the license file to fail, while still locked.

Can you please check your code to access the licencse file in regards to concurrency? If you are locking the file, can you please avoid doing so?

Any other suggestions/ideas that might help us overcome this problem?

Thanks!

Hello

Which exactly Hydra version do you use? This (or a very similar) issue should have been fixed in one of the latest releases.

Also do your Delphi host applications instantiate plugins from several threads at once?

Regards

Hello,

we use Hydra 5.0.89.1157.
No that plugin is instantiated only from the main thread.

Thanks!

Coul you try to update to the latest Beta to see if this behavior persist?

There is no such thing as license file. License checks are performed based on a precompiled license information bundled with the plugin assembly (this is how the .NET licensng system works).

Note that err_CannotInstantiateManagedPlugin doesn’t necessarily means that there was license error. This could be a different exceptin thrown in the constructor. Do you have any complex logic in the plugin constructor?

(which should be thread-safe and re-entrant, as far as I know)

@antonk @mh

Thanks for the info.

Just to clarify, we are not using multiple threads, but multiple independent processes (exe’s).

The problem seems to be these processes are all trying to access the same plugin assembly simultaneously.

The problem has never happened when only one process is involved, but only started to appear once multiple processes were involved.

My guess is that:
The plugin assembly is locked for a short period during startup. If another process then tries to access the assembly while locked, it fails and generates the err_CannotInstantiateManagedPlugin error.
I am guessing the assembly gets locked when Hydra is loading it/checking the license file. So maybe you could check to see if the assembly is locked during loading.
Unfortunately I have no clue as to when the lock starts/ends.
What I do know is that the lock must not last long, otherwise this problem would occur every time. The problem only happens sporadically.

Thanks again!

Hello

Could you try to update to the latest Hydra beta? It will provide more exception info. Also coult you send to support@ your code (strip out the actual business logic, I only need to take a look at its constructor/initialization code and code-behind file)?

Thanks in advance

Hi,

we encountered the same issue. Could you solve it? How?

Thanks in advance.

Hello

Any chances you could create a (small) testcase where this issue reproduces?

Thanks in advance

Issue solved (see 15668).