Skip to content

Jetty should start only on active broker (not on passive) #1920

@jbonofre

Description

@jbonofre

I observed a race condition where the Jetty server can start on passive broker (slave), whereas it should not be the case.

The problem is that Jetty server is not a broker service, so Jetty doesn't consider the broker type (active or passive).

I investigated and I found the sequence explaining this behavior:

  1. BrokerService.@PostConstruct -> autostart() -> start() is called
  2. With startAsync=true, startPersistenceAdapter() and startBroker() both launch background threads and return immediately
  3. At this point slave=true - the broker is still waiting to acquire the file/JDBC lock
  4. Spring continues initializing the remaining beans from jetty.xml
  5. The invokeStart bean - a MethodInvokingFactoryBean that calls Server.start() - fires unconditionally during Spring context initialization
  6. Jetty is now running on the passive/slave

The passive/slave stays in this state (Jetty up, broker passive) until the master fails. Then the background thread acquires the lock, calls startAllConnectors(), and slave becomes false. But Jetty was already running 😄

NB: this case only happens with startAsync=true in a master/slave configuration - a combination that's commonly recommended to avoid blocking the Spring context during lock contention.

NB: this case doesn't happen with startAsync=false: BrokerService.@PostConstruct blocks until the broker fully starts (lock acquired -> startAllConnectors() -> startedLatch.countDown()). Spring only continues to the jetty.xml beans after that. By then the broker is already master/active, so invokeStart fires the right time.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

Status

In Progress

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions