Skip to content

Commit d11d12e

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Perform scheduled check based on latest acquired Version instance
Version instance can be updated in the meantime, however this is not critical and it helps to avoid synchronization issues DEVSIX-5515 Autoported commit. Original commit hash: [427b4ef12]
1 parent 78b6372 commit d11d12e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

itext/itext.kernel/itext/kernel/Version.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,24 @@ internal Version(VersionInfo info, bool expired) {
116116
/// <see cref="Version"/>.
117117
/// </returns>
118118
public static iText.Kernel.Version GetInstance() {
119-
lock (staticLock) {
120-
if (version != null) {
121-
try {
122-
LicenseScheduledCheck();
123-
}
124-
catch (Exception e) {
125-
// If any exception occurs during scheduled check of core license,
126-
// then it means that license is not valid yet, so roll back to AGPL.
127-
// The key value is null as it is similar to case
128-
// when an exception has been thrown during initial license loading
129-
AtomicSetVersion(InitAGPLVersion(e, null));
130-
}
131-
return version;
119+
iText.Kernel.Version localVersion = version;
120+
// It's crucial to work with 'localVersion' local variable, because 'version' field can be
121+
// changed by some other thread. We also don't want to block Version class lock when calling
122+
// for scheduled check in order to avoid synchronization issues with parallel loading license.
123+
if (localVersion != null) {
124+
try {
125+
LicenseScheduledCheck(localVersion);
126+
return localVersion;
127+
}
128+
catch (Exception e) {
129+
// If any exception occurs during scheduled check of core license it means that
130+
// license is not valid, in this particular case we want to reset to AGPL Version,
131+
// however "normal" initialization logic will not switch to AGPL unless license is
132+
// unloaded.
133+
// not saving this AGPL version in order to avoid race condition with loaded proper license
134+
return InitAGPLVersion(e, null);
132135
}
133136
}
134-
iText.Kernel.Version localVersion;
135137
String key = null;
136138
try {
137139
String coreVersion = release;
@@ -418,8 +420,8 @@ private static iText.Kernel.Version AtomicSetVersion(iText.Kernel.Version newVer
418420
}
419421
}
420422

421-
private static void LicenseScheduledCheck() {
422-
if (version.IsAGPL()) {
423+
private static void LicenseScheduledCheck(iText.Kernel.Version localVersion) {
424+
if (localVersion.IsAGPL()) {
423425
return;
424426
}
425427
String licenseKeyProductFullName = "iText.License.LicenseKeyProduct, itext.licensekey";

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
433785f469b0d85733c0b170e7403a445044e3ed
1+
427b4ef12f5518f96006747f22ada788b9eb21a7

0 commit comments

Comments
 (0)