Skip to content

8.0 (fix): Load what the embedded MongoDB's event loops need as it starts - #16878

Closed
codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/embedded-mongo-first-read-8.0.x
Closed

codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/embedded-mongo-first-read-8.0.x

Conversation

@codeconsole

@codeconsole codeconsole commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This does not fix a problem 8.x has. I opened it believing 8.x would hang like this once it moves to Spring Boot 4.1.3, and that was wrong, as is the same sentence in the commit message. The hang needs spring-projects/spring-boot#52246 as well as #52582, and only 4.2 has both. With the loader of 4.1.3-SNAPSHOT and the fix taken out, the application stopped cleanly 10 times out of 10, where the loader of 4.2.0-RC2 hung 3 times out of 3. The fix for 9.1.x is in #16871, and Spring Boot's own is proposed in spring-projects/spring-boot#52635.

What is left here is hardening: InMemoryMongoBackend has the server answer one isMaster as it starts, so the event loop has loaded what its first client needs before that client connects. ClearedJarsServerApplication and EmbeddedMongoLifecycleSpec cover it, and the spec fails without the change on this branch.

Spring Boot closes the jars of an executable jar's class loader when the
context has refreshed, through ClearCachesApplicationListener, and a class
being loaded at that moment fails with IllegalStateException: Zip file
closed. That listener did not reach the class loader until Spring Boot
4.2.0-RC2, 4.1.3 and 4.0.10 (spring-projects/spring-boot#52582), so 8.0.x
meets this when it moves to 4.1.3. It is reported as
spring-projects/spring-boot#52634.

The driver connects just before that moment, and reading its first bytes
allocates the event loop's first buffer. Netty logs the failure, Logback
fails the same way to load a class to log it, and that ends the event loop's
thread. The driver gets no answer, and stopping the server waits forever for
its connection on that thread to close. On 4.2.0-RC2 an application with the
in-memory backend run from its executable jar hung when stopped 3 times out
of 3 with Netty 4.2.20 and 1 out of 6 with Netty 4.2.19.

The server now answers one isMaster as it starts, so the event loop has
loaded what the first client needs long before that moment. The race remains
for anything else loading a class right then.

ClearedJarsServerApplication fails class loading for a moment as a client
sends its first bytes. The spec fails without this.
@codeconsole

Copy link
Copy Markdown
Contributor Author

Closing: 8.x does not have this problem. The hang needs spring-projects/spring-boot#52246 as well as #52582, and only 4.2 has both. With the loader of 4.1.3-SNAPSHOT and this change taken out, the application stopped cleanly 10 times out of 10. The change remains in #16871 for 9.1.x, and Spring Boot's fix is proposed in spring-projects/spring-boot#52635.

@codeconsole codeconsole closed this Nov 6, 2026
@codeconsole
codeconsole deleted the fix/embedded-mongo-first-read-8.0.x branch November 6, 2026 04:13
@codeconsole codeconsole removed this from the grails:8.0.1 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant