Move call of stopIncomingRequests before lifecycler shutdown. #2219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lifecycler was recently refactored (by #2166), which unfortunately breaks some expectations in Loki. This PR makes fixing Loki possible.
Before #2166, Lifecycler's
Shutdown
method calledflushTransferer.StopIncomingRequests()
and only then stopped lifecycler's loop.After #2166, this has been modified. Lifecycler is now stopped via
StopAsync
method (through embedded BasicService), which cancels context used byloop()
method, which makesloop()
exit.stopping()
method is called afterwards. This method still callsflushTransferer.StopIncomingRequests()
, but by this time,loop
has already finished.In Cortex, this doesn't make much difference – only Ingester implements
StopIncomingRequests
method with non-empty body, and it simply sets the readonly flag. In Loki,StopIncomingRequests
blocks until data transfer has finished, but it expects loop to be still running.Solution to the issue is removing
StopIncomingRequests
fromFlushTransferer
interface – logically, it doesn't belong there anyway – and let Ingester call it explicitely before stopping the lifecycler. This reverts the method call order back to original.Why doesn't
StopIncomingRequests
belong toFlushTransferer
? All otherFlushTransferer
methods are called by lifecycler after main lifecycler loop has exited, during lifecycler's shutdown process.StopIncomingRequests
was the only method that was called before triggering lifecycler's shutdown procedure.(Fix in Loki is the same – call StopIncomingRequests from Ingester's shutdown method, before stopping the lifecycler. I have patch, incl. Cortex update ready.)
cc @rfratto