-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force class load on UserRequest, see JENKINS-19445 #82
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,10 +86,32 @@ public UserRequest(Channel local, Callable<?,EXC> c) throws IOException { | |
return result; | ||
} | ||
|
||
static boolean workaroundDone = false; | ||
protected UserResponse<RSP,EXC> perform(Channel channel) throws EXC { | ||
try { | ||
ClassLoader cl = channel.importedClassLoaders.get(classLoaderProxy); | ||
|
||
// Allow forcibly load of a class, allows to workaround: | ||
// @See https://issues.jenkins-ci.org/browse/JENKINS-19445 | ||
// @Related https://issues.tmatesoft.com/issue/SGT-451 | ||
final String clazz = System.getProperty(RemoteClassLoader.class.getName() + ".force", null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would vote for initializing it once as a static variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only point we are certain to have the same ClassLoader with the same rules. Not sure how to obtain the same ClassLoader from a static block. We checked all the flow from Launcher to here, as the only point were it would be safe, and early enough to prevent the blockage. |
||
if ( clazz != null && !workaroundDone) { | ||
// java.lang classes can only be instantiated by the bootstrap Classloader. | ||
// Guarantees that *all* threads with whatever Classloader in use, have the | ||
// same mutex instance: an intance of java.lang.Class<java.lang.Object> | ||
synchronized(java.lang.Object.class) | ||
{ | ||
workaroundDone = true; | ||
try { | ||
final Class<?> loaded = Class.forName( clazz, true, cl ); | ||
System.err.println("Loaded class: '" + clazz + "' using classloader: " + cl); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Jenkins project we commonly use class name as a logger name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are using RemoteClassLoader for the property, I used the same class for logging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
} catch (final ClassNotFoundException cnfe) { | ||
// not big deal, print and swallow exception | ||
System.err.println("Error finding class '" + clazz + "' using classloader: " + cl); | ||
} | ||
} | ||
} | ||
|
||
RSP r = null; | ||
Channel oldc = Channel.setCurrent(channel); | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, many time away from coding in Java.