https://issues.apache.org/bugzilla/show_bug.cgi?id=52718
Bug #: 52718 Summary: An incomplete fix for the resource leak bug in NioEndpoint.java Product: Tomcat 6 Version: unspecified Platform: PC Status: NEW Severity: critical Priority: P2 Component: Connectors AssignedTo: dev@tomcat.apache.org ReportedBy: liangg...@sei.pku.edu.cn Classification: Unclassified The fix revision 424429 was aimed to remove an resource leak bug on the SocketChannelobject "channel" in the method "findJarServiceProvider" of the file "/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java" , but it is incomplete. When the statements at lines 1142-1153 or line 1162 throw any eception, the object "channel" can not be closed as expected. The best way to close such resource object is putting such close operations in the finally block. This problem is not handled in the head revision of tomcat 6.0 and also tomcat 7.0. The code in the head revision needing to be inspected is as bellow: public void run() { // Loop until we receive a shutdown command while (running) { // Loop if endpoint is paused while (paused) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore } } boolean hasEvents = false; hasEvents = (hasEvents | events()); // Time to terminate? if (close) return; int keyCount = 0; try { keyCount = selector.select(selectorTimeout); } catch (Throwable x) { log.error("",x); continue; } //either we timed out or we woke up, process events first if ( keyCount == 0 ) hasEvents = (hasEvents | events()); //if (keyCount == 0) continue; Iterator iterator = keyCount > 0 ? selector.selectedKeys().iterator() : null; // Walk through the collection of ready keys and dispatch // any active event. while (iterator != null && iterator.hasNext()) { SelectionKey sk = (SelectionKey) iterator.next(); iterator.remove(); KeyAttachment attachment = (KeyAttachment)sk.attachment(); try { if ( sk.isValid() ) { if(attachment == null) attachment = new KeyAttachment(); attachment.access(); sk.attach(attachment); int readyOps = sk.readyOps(); sk.interestOps(sk.interestOps() & ~readyOps); SocketChannel channel = (SocketChannel)sk.channel(); [1142] boolean read = sk.isReadable(); if (read) { if ( attachment.getWakeUp() ) { attachment.setWakeUp(false); synchronized (attachment.getMutex()) {attachment.getMutex().notifyAll();} } else if ( attachment.getComet() ) { if (!processSocket(channel,false)) processSocket(channel,true); } else { boolean close = (!processSocket(channel)); if ( close ) { channel.socket().close(); 【1154】 channel.close(); } } } } else { //invalid key cancelledKey(sk); } } catch ( CancelledKeyException ckx ) { [1162] if (attachment!=null && attachment.getComet()) processSocket( (SocketChannel) sk.channel(), true); try { sk.channel().close(); }catch ( Exception ignore){} } catch (Throwable t) { log.error("",t); } }//while //process timeouts timeout(keyCount,hasEvents); }//while synchronized (this) { this.notifyAll(); } } -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org