Bug 65708 - uncaptured exception make SocketProcessor container has a httpconnection leak
Summary: uncaptured exception make SocketProcessor container has a httpconnection leak
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.23
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-28 10:17 UTC by newchaos@sina.com
Modified: 2021-12-02 10:53 UTC (History)
0 users



Attachments
the line 1476 encounter a exception (108.19 KB, image/png)
2021-11-28 10:17 UTC, newchaos@sina.com
Details

Note You need to log in before you can comment on or make changes to this bug.
Description newchaos@sina.com 2021-11-28 10:17:06 UTC
Created attachment 38104 [details]
the line 1476 encounter a exception

tomcat-embed-core-8.5.23.jar

if org.apache.tomcat.util.net.NioEndpoint.SocketProcessor#doRun  encounter exception before connection closed and it is not CancelledKeyException class,it will trigger throw exception to the third catch code block. 


if org.apache.tomcat.util.net.NioEndpoint.SocketProcessor#doRun (line 1453 -- line 1485)

                if (handshake == 0) {
                    SocketState state = SocketState.OPEN;
                    // Process the request from this socket
                    if (event == null) {
                        state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ);
                    } else {
                        state = getHandler().process(socketWrapper, event);
                    }
                    if (state == SocketState.CLOSED) {
                        close(socket, key);
                    }
                } else if (handshake == -1 ) {
                    close(socket, key);
                } else if (handshake == SelectionKey.OP_READ){
                    socketWrapper.registerReadInterest();
                } else if (handshake == SelectionKey.OP_WRITE){
                    socketWrapper.registerWriteInterest();
                }
            } catch (CancelledKeyException cx) {
                socket.getPoller().cancelledKey(key);
            } catch (VirtualMachineError vme) {
                ExceptionUtils.handleThrowable(vme);
            } catch (Throwable t) {
                log.error("", t);
                socket.getPoller().cancelledKey(key);
            } finally {
                socketWrapper = null;
                event = null;
                //return to cache
                if (running && !paused) {
                    processorCache.push(this);
                }
            }


and in the catch block  if the first line code(line 1476) encounter exception, the second line code(line 1477) will be skip. and the socket will be not closed, ,and make a socket connection  leak.
Comment 1 Mark Thomas 2021-12-02 10:53:38 UTC
If

log.error("",t)

throws an exception you have much bigger problems than a connection leak. Once things start to go that badly wrong, it is not practical to handle all possible errors.