You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java HttpsURLConnection报“Received close_notify during handshake”错误问询

Troubleshooting Connection Termination with HttpsURLConnection Behind Proxy (JDK 1.6)

Hey there, let's break down why your connection might be getting terminated when calling conn.getInputStream();—even though you didn't close it on the client side. Since you're on JDK 1.6 (which is pretty outdated, for what it's worth), there are a few key culprits to check:

1. Proxy Server Timed Out the Idle Connection

Most proxies enforce idle timeouts to free up resources. If there's a delay between when you establish the connection and when you call getInputStream(), the proxy might have already dropped the connection because it didn't see any activity.

JDK 1.6's HttpsURLConnection has relatively long default timeouts, but if your proxy's timeout is shorter, this will happen. Try explicitly setting connection and read timeouts to match your proxy's settings:

conn.setConnectTimeout(30000); // 30 seconds
conn.setReadTimeout(30000);

2. JDK 1.6's Limited TLS Protocol Support

JDK 1.6 defaults to TLS 1.0, and many modern proxies or backend servers have disabled TLS 1.0 due to security vulnerabilities. If the proxy/server refuses to negotiate TLS 1.0, the handshake will fail, and the connection gets terminated.

Depending on your JDK 1.6 update version (update 111+ supports TLS 1.1), you can try forcing a newer protocol via system properties:

-Dhttps.protocols=TLSv1,TLSv1.1

Check your SSL logs for lines like "no suitable protocol" or "handshake failure" to confirm this is the issue.

3. Connection Reuse Bugs in JDK 1.6's Connection Pool

HttpsURLConnection reuses connections by default, but JDK 1.6 has known issues with connection pooling, especially when working with proxies. If the pool tries to reuse a connection that the proxy already closed, you'll get a termination error.

Try disabling connection reuse to test this:

conn.setRequestProperty("Connection", "close");

If the problem goes away, you know it's a pooling-related bug.

4. SSL Certificate Validation Failures

If your backend server's SSL certificate isn't trusted by JDK 1.6's default cacerts store, the SSL handshake will fail, and the proxy/server will drop the connection. Look for lines like "unable to find valid certification path to requested target" in your SSL logs.

To fix this, you'll need to import the server's CA certificate into JDK 1.6's cacerts file using the keytool command.

5. Missing Proxy Authentication

If your proxy requires authentication but you haven't configured it, the proxy might accept the initial connection but terminate it when it realizes you're not authenticated.

Set the proxy credentials via system properties:

System.setProperty("https.proxyUser", "your-username");
System.setProperty("https.proxyPassword", "your-password");

Double-check that you're using the right properties (https.proxy* for HTTPS proxies, http.proxy* for HTTP proxies).

Don't forget to dig into the details of your SSL logs—they usually have specific error messages that can narrow down the exact cause quickly.

内容的提问来源于stack exchange,提问作者Srijith Kartha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:03:23