-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Closed
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com
Description
I have a problem with a database connection pool in Spring Boot 2, where connections are not returned to the pool even though they are neatly wrapped in @Transactional
.
Upon opening the home page, I run a query and then open an SSE stream:
@GetMapping("")
public SseEmitter home() {
derpService.derp();
return obs.subscribeSse();
}
The derp()
call looks like this:
@Transactional
void derp() {
derpRepository.derp();
}
Which leads to:
@Query(value = "SELECT 'derp'", nativeQuery = true)
void derp();
As long as the SSE stream is open, the connection from the derp()
call is not released. This goes against my intuition, because I assumed @Transactional
would return the connection as soon as the flow exits the transaction scope.
Is this a bug in Spring?
Steps to reproduce
- Open the minimal example (link below)
- Run
docker-compose up -d --build
- Start the application
- Open
http://localhost:8088
in six tabs - The sixth tab will not load because all connections are in use.
Resources
- Minimal example on https://github.com/Oduig/connectionleak.
- SO question on https://stackoverflow.com/questions/49071931/database-connection-leak-in-spring-boot-with-sseemitter
Divine1 and zhfkt
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com