Potential deadlock in TransportKeyManager
TransportKeyManager uses the single-threaded DatabaseExecutor to ensure its DB tasks write to the DB in the same order as they're queued. This makes it possible to keep TransportKeyManager's internal state consistent with the state of the DB without holding locks during DB calls.
To ensure that a StreamContext is never used twice, the two getStreamContext() methods wait for their DB tasks to complete before returning. This will cause deadlock: if the methods are called on the DatabaseExecutor thread, as their DB tasks will be queued behind them and will never complete.
One way to fix this would be for TransportKeyManager to keep its own single-threaded executor for running its DB tasks. KeyManagerImpl already has a Timer thread that could be converted into an executor.
Another possibility would be to return a Future.