There is a race condition revealed by failing test KafkaStreamsTest#testCannotStartTwise. It fails with:
The race condition is a follows:
1) test calls KafkaStreams#start() for the first time and state transits from CREATED -> RUNNING
2) First poll triggers a rebalance and StreamThread put KafkaStreams into state REBALANCING
3) before REBALANCING completes, the main test thread calls KafkaStream#start() again. As current state is REBALANCING, the transition to RUNNING is valid and start() does not fail with IllegalStateException but resumes. When it tries to start internal streams, we get IllegalThreadStateException as thread are already running.