Skip to content
Permalink
Browse files
Merge branch 'test-fix-2333' into jruby-1_7
  • Loading branch information
headius committed Dec 22, 2014
2 parents 287cb36 + bd79165 commit 4f21b1ec4c7d2fae620a589315adddbcc5f05696
@@ -3223,6 +3223,11 @@ public void tearDown(boolean systemExit) {
getJRubyClassLoader().tearDown(isDebug());
}

// Unregister stdio ChannelDescriptors so they don't leak
ChannelDescriptor.unregisterDescriptor(getFilenoExtMap(0));
ChannelDescriptor.unregisterDescriptor(getFilenoExtMap(1));
ChannelDescriptor.unregisterDescriptor(getFilenoExtMap(2));

if (config.isProfilingEntireRun()) {
// not using logging because it's formatted
ProfileCollection profileCollection = threadService.getMainThread().getContext().getProfileCollection();
@@ -48,6 +48,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -863,13 +864,17 @@ private static void registerDescriptor(ChannelDescriptor descriptor) {
filenoDescriptorMap.put(descriptor.getFileno(), descriptor);
}

private static void unregisterDescriptor(int aFileno) {
public static void unregisterDescriptor(int aFileno) {
filenoDescriptorMap.remove(aFileno);
}

public static ChannelDescriptor getDescriptorByFileno(int aFileno) {
return filenoDescriptorMap.get(aFileno);
}

public static Map<Integer, ChannelDescriptor> getFilenoDescriptorMapReadOnly() {
return Collections.unmodifiableMap(filenoDescriptorMap);
}

private static final Map<Integer, ChannelDescriptor> filenoDescriptorMap = new ConcurrentHashMap<Integer, ChannelDescriptor>();

@@ -72,6 +72,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ClassCache;
import org.jruby.util.KCode;
import org.jruby.util.io.ChannelDescriptor;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -2757,4 +2758,16 @@ public void testClasspathScriptletHasClasspathFile() {
Object result = instance.runScriptlet(PathType.CLASSPATH, "__FILE__.rb");
assertEquals("classpath:/__FILE__.rb", result.toString());
}

@Test
public void testContainerScrubsStdioDescriptors() {
Map<Integer, ChannelDescriptor> orig = ChannelDescriptor.getFilenoDescriptorMapReadOnly();

ScriptingContainer instance = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
instance.runScriptlet("1");

instance.terminate();

assertEquals(orig, ChannelDescriptor.getFilenoDescriptorMapReadOnly());
}
}

0 comments on commit 4f21b1e

Please sign in to comment.