javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

ConcurrentModificationException in mutithread-looping client #1809

Closed glassfishrobot closed 9 years ago

glassfishrobot commented 9 years ago

the following code produces ConcurrentModificationException:

private static final int N_THREADS = Runtime.getRuntime().availableProcessors() * 2; private final ExecutorService executor = Executors.newFixedThreadPool(N_THREADS);

@Test public void testGrizzlyLite() throws InterruptedException {

final CountDownLatch cdl = new CountDownLatch(N_THREADS);

for (int i = 0; i < N_THREADS; i++) { executor.execute(new Runnable() { @Override public void run() { while (true) { try

{ FilterChainBuilder filterChain = FilterChainBuilder.stateless(); filterChain.add(new TransportFilter()); throw new IOException(filterChain.build() + "aa"); }

catch (IOException e) {

} } } }); } cdl.await(); }

Running org.dcache.xdr.GrizzlyBugTest Exception in thread "pool-1-thread-12" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) at java.util.ArrayList$Itr.next(ArrayList.java:851) at org.glassfish.grizzly.filterchain.ListFacadeFilterChain.addAll(ListFacadeFilterChain.java:96) at org.glassfish.grizzly.filterchain.FilterChainBuilder$StatelessFilterChainBuilder.build(FilterChainBuilder.java:152) at org.dcache.xdr.GrizzlyBugTest$1.run(GrizzlyBugTest.java:41) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

This is triggered by GC calling AbstractFilterChain#finalize(); Somehow the list is still in use. I don;t know is it grizzly issue or JVM.

Neverhteless, there are no reasons why FilterChainBuilder uses DefaultFilterChain to keep list of defined filters. Changing it to regular ArrayList fixes the issue.

Regards, Tigran.

Environment

$ uname -a Linux ani 4.1.10-200.fc22.x86_64 #1 SMP Mon Oct 5 14:22:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux $ java -version openjdk version "1.8.0_60" OpenJDK Runtime Environment (build 1.8.0_60-b27) OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

Affected Versions

[2.3.22]

glassfishrobot commented 9 years ago

Reported by kofemann

glassfishrobot commented 9 years ago

kofemann said: fix: https://github.com/GrizzlyNIO/grizzly-mirror/pull/5 (why I cant attach patch ?)

glassfishrobot commented 9 years ago

@rlubke said: Because the j.net infrastructure has it disabled for all but project committers due to spam. Not a fan of it myself, but out of our control. Thanks for the pull request. Will review shortly.

glassfishrobot commented 9 years ago

@rlubke said: Changes applied: c33c038

No need to port to master.

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA GRIZZLY-1809

glassfishrobot commented 9 years ago

Marked as fixed on Thursday, October 15th 2015, 12:06:13 pm