Spring Boot Jdbc javax.net.ssl.SSLException closing inbound before receiving peer's close_notify
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The exception javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify appears when Java shuts down a TLS connection and realizes the remote side closed the socket without sending the normal TLS shutdown alert. In a Spring Boot JDBC application, that usually means the problem sits in the database server, proxy, load balancer, or JDBC driver interaction rather than in Spring Boot itself. The first step is to determine whether the exception is merely noisy shutdown logging or an actual failed database operation.
What the Error Means
TLS connections are supposed to end with a close_notify alert from each side. Java's JSSE implementation tracks that state. If the peer simply drops the TCP connection, Java may complain when the socket is closed cleanly on the client side.
That leads to an important distinction:
- if your query succeeds and the exception appears only while closing the connection, the issue is often a shutdown-protocol mismatch or buggy peer behavior
- if the query itself fails, treat it as a real connectivity problem and inspect TLS versions, certificates, proxies, and driver configuration
In other words, the same message can be harmless noise in one system and a symptom of a broken TLS path in another.
Start by Verifying the JDBC Path
Use a minimal query with normal resource handling so you know the exception is not caused by application misuse.
If this succeeds consistently but you still see the SSL exception during pool cleanup, focus on the network peer and driver rather than on the SQL logic.
Configure TLS Explicitly Instead of Relying on Defaults
A common cause of brittle TLS behavior is vague connection settings. Be explicit in the JDBC URL and trust-store configuration.
For PostgreSQL, a Spring Boot configuration might look like this:
For MySQL or MariaDB, the equivalent parameters differ, but the principle is the same: define a clear SSL mode and use a driver version that matches your server.
When you route traffic through a proxy, managed database endpoint, or TLS-terminating middlebox, confirm that it preserves correct TLS shutdown behavior. Java is often stricter than other clients about protocol correctness, so an intermediary that appears "good enough" elsewhere may still generate this warning in JDBC workloads.
Gather Evidence With TLS Debug Logging
Before changing random flags, capture one failing connection with JSSE debug logging:
That output is noisy, but it tells you whether the handshake succeeded, which protocol version was negotiated, and whether the peer sent a proper close alert.
If the handshake is clean and only the shutdown is imperfect, the likely fixes are:
- upgrade the JDBC driver
- upgrade the JDK if you are on an old patch level
- check the database server or proxy TLS implementation
- reduce unnecessary connection churn so the pool does not constantly create and retire sockets
Connection Pools Matter
Spring Boot commonly uses HikariCP. In practice, many close-notify warnings appear during connection retirement rather than during active queries. Pool settings can reduce the frequency of that path.
For example, a reasonable keepalive helps prevent stale idle sockets from being rediscovered at an awkward moment:
This is not a cure for a misbehaving TLS peer, but it can make connection turnover more predictable and easier to diagnose.
What Not to Do
Do not "fix" this by disabling certificate validation or by downgrading to plaintext database traffic unless you have an isolated development environment and an explicit reason. That hides the symptom by removing security, not by correcting the protocol path.
Also avoid adding obscure JVM SSL properties unless you can explain what they change. JSSE has options related to close-notify behavior, but if the peer never sends the TLS shutdown alert, the durable fix is still on the server, proxy, or driver side.
Common Pitfalls
The most common mistake is blaming Spring Boot because the stack trace appears in Spring logs. Spring Boot usually just surfaces the JDBC exception; it does not implement the TLS protocol itself.
Another mistake is treating every appearance of this message as fatal. If the SQL work completed successfully, you may be looking at shutdown noise rather than a broken application path.
Teams also often debug only the application and forget the network boundary. Load balancers, proxies, database firewalls, and managed service endpoints can all terminate TLS in ways that trigger this warning.
Finally, do not ignore driver and JDK versions. TLS behavior and shutdown handling improve over time, so "update the driver and runtime first" is not hand-waving here. It is one of the highest-value checks.
Summary
- The exception means Java closed TLS inbound processing before the peer sent
close_notify. - In JDBC applications, the root cause is often the database peer, proxy, or driver interaction rather than Spring Boot itself.
- First determine whether the query failed or whether the warning appears only during connection shutdown.
- Configure TLS explicitly, capture JSSE debug logs, and check driver and JDK versions.
- Do not hide the issue by disabling SSL verification or downgrading security.
Related reading
- Spring Boot JPA2 Hibernate - enable second level cache
- Spring Boot JPA - configuring auto reconnect
- Spring Boot JPA Column name annotation ignored
- Spring Boot JPA Column name annotation ignored
- Spring Boot Kafka Commit cannot be completed since the group has already rebalanced
- Spring Boot Kafka Configure DefaultErrorHandler?
- Spring Boot JSF Integration
- Spring Boot JSP 404

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.