Give up on ListenBrainz requests that never answer - #8
Open
sav wants to merge 2 commits into
Open
Conversation
Submitting happens inside the polling loop with no timeout on the client, so a request left hanging by a dropped network stopped everything: MPD was not polled and the connection never recovered, for as long as the socket stayed open. One outage kept the loop stuck for over an hour.
A submission that fails is logged, but nothing is logged once one succeeds, so a log that ends in timeouts gives no way to tell a connection that is still down from one that recovered. Remember that a submission failed and let the next successful one say so, once, mirroring what the MPD connection already reports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Submitting happens inside the polling loop, and the HTTP client had no timeout. A request left hanging by a dropped network stopped the whole loop: MPD was not polled,
connect()never ran, and the connection never recovered — for as long as the socket stayed open.Seen in the wild after a night of radio: the process went 1h42 without a single log line, with
-von, while the machine stayed awake the whole time.Restarting MPD changed nothing, because mpd-brainz was not looking at MPD — it was stuck in a POST to
api.listenbrainz.org.The fix
One shared
http.Clientwith a 10s timeout, instead of a fresh&http.Client{}per submission.Testing
A server that accepts the connection and never answers, with MPD restarted mid-request:
Submititself now returns in 10s (Client.Timeout exceeded while awaiting headers) instead of never. The rest of the suite still passes.Worth knowing
With ListenBrainz down, one tick can spend two timeouts — the announcement and the listen — so 20s. At the default 30s interval that keeps cycles under MPD's 60s
connection_timeout, but not by much, and it is what produces the repeatedlost connection: EOFlines in the log above. Not reinsisting onplaying_nowevery tick after it fails would halve it.