theonedev/onedev · error · ServerNotReadyException
Server not ready
Error message
Server not ready
What it means
DefaultSessionService opens a thread-local Hibernate Session lazily via ObjectReference.openObject(). If SessionFactoryService has not yet built the SessionFactory (database not initialized/configured), a ServerNotReadyException with message "Server not ready" is thrown instead of returning a session. It signals that the caller attempted DB access during startup or before/while the server is shutting down.
Source
Thrown at server-core/src/main/java/io/onedev/server/persistence/DefaultSessionService.java:48
@Inject
private SessionFactoryService sessionFactoryService;
private final ThreadLocal<ObjectReference<Session>> sessionReferenceHolder = new ThreadLocal<ObjectReference<Session>>() {
@Override
protected ObjectReference<Session> initialValue() {
return new ObjectReference<Session>() {
@Override
protected Session openObject() {
SessionFactory sessionFactory = sessionFactoryService.getSessionFactory();
if (sessionFactory != null) {
Session session = sessionFactory.openSession();
// Session is supposed to be able to write only in transactional methods
session.setHibernateFlushMode(FlushMode.MANUAL);
return session;
} else {
throw new ServerNotReadyException();
}
}
@Override
protected void closeObject(Session session) {
session.close();
}
};
}
};
@Override
public void openSession() {
sessionReferenceHolder.get().open();
}
View on GitHub (pinned to d44925c47c)
Solutions
- Wait until server startup completes (DB initialized) before doing DB work; defer work to an appropriate post-startup hook/listener
- Wrap early-phase DB access with sessionService.call() which no-ops gracefully when the SessionFactory is null
- Check sessionFactoryService.getSessionFactory() != null before calling getSession()/openSession()
- If this appears on every request after startup, check server logs for a DB initialization failure that left the server not ready
Example fix
// before
var session = sessionService.getSession();
// after
if (sessionFactoryService.getSessionFactory() != null) {
var session = sessionService.getSession();
} else {
logger.info("Server not ready yet; deferring DB work");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (sessionFactoryService.getSessionFactory() == null) {
throw new IllegalStateException("Server not ready; defer DB access");
} Type guard
boolean serverReady() { return sessionFactoryService.getSessionFactory() != null; } Try / catch
try {
sessionService.run(() -> dao.doWork());
} catch (ServerNotReadyException e) {
logger.info("Server not ready; retrying later", e);
scheduleRetry();
} Prevention
- Do DB work only from post-startup hooks, not constructors/init phases
- Prefer sessionService.call()/run() which handles the not-ready case
- Check sessionFactoryService.getSessionFactory() before direct session access
- Watch startup logs for DB init failures
When it happens
Trigger: Calling sessionService.openSession(), getSession(), or running code inside sessionService.call()/run() before the SessionFactory exists — i.e. during OneDev bootstrap before DB upgrade/initialization completes, or after it was torn down.
Common situations: Plugin or extension code touching the database in an early startup/lifecycle phase; background threads started before DB init; accessing sessionService during server shutdown; REST/web requests arriving while server is still initializing.
Related errors
- Unrecognized command:
- Unable to discover cluster ip from database connection url:
- Base resource mapper should be used
- Cannot determine Markup. Component is not yet connected to a
- has not been properly initialized. Something in the hierarc
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/84a395e998188ad4.
Report an issue: GitHub.