Skip to content
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

Subscriber.lookupTopic doesn't close connections, leading to excessive ESTABLISHED connections #92

Open
yikuo123 opened this issue Jan 7, 2025 · 1 comment · Fixed by yikuo123/nsq-j#1 · May be fixed by #93
Open

Comments

@yikuo123
Copy link

yikuo123 commented Jan 7, 2025

I observed a large number of TCP connections in the ESTABLISHED state. It appears that the method may not be properly closing connections after the request is completed, causing connections to remain open and accumulate over time.

Should we explicitly call con.disconnect() to ensure connections are properly closed after use?

tcp6       0      0 172.25.148.212:42058    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:53202    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:57892    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:43808    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:52334    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:56484    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:4161     172.25.148.212:52334    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:51564    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:36432    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:50028    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:46972    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:59220    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:36368    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:49010    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:45846    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:55636    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:52328    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:55424    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:37510    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:59684    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:4161     172.25.148.212:51920    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:4161     172.25.148.212:45644    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:4161     172.25.148.212:40490    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:4161     172.25.148.212:51912    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:46706    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:51912    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:35188    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:58828    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:42174    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:59814    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:47186    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:56956    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:51920    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:48244    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:44146    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:53786    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:41250    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:34934    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:50028    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:58136    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:49852    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:4161     172.25.148.212:47186    ESTABLISHED 986/nsqlookupd      
tcp6       0      0 172.25.148.212:44186    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:39392    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:54300    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:59604    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:57280    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:59292    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:41762    172.25.148.212:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:50108    172.25.148.213:4161     ESTABLISHED 3888/java           
tcp6       0      0 172.25.148.212:57480    172.25.148.213:4161     ESTABLISHED 3888/java
@yikuo123
Copy link
Author

yikuo123 commented Jan 7, 2025

if (con.getResponseCode() != 200) {
    logger.debug("ignoring lookup resp:{} nsqlookupd:{} topic:{}", con.getResponseCode(), lookup, topic);
    continue;
}
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
finally {
    Util.closeQuietly(in);
}

Even though closing the InputStream typically triggers HttpURLConnection to automatically close the connection, in the case where the response code is non-200 (i.e., a failure response), the InputStream is not read, and thus the connection is not automatically closed. In such scenarios, the connection remains open unless explicitly disconnected.

Should we explicitly call con.disconnect() in cases where the response code is not 200, or is there another recommended way to ensure the connection is properly closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant