Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisConnection#Connect(): get rid of spin lock #10265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented Dec 6, 2024

Instead of IoEngine::YieldCurrentCoroutine(yc) until m_Queues.FutureResponseActions.empty(), async-wait a CV which is updated along with m_Queues.FutureResponseActions.

👍 Re-connect still works on Redis restart, even if latter interrupted an outgoing message!

[2024-12-06 10:24:02 +0100] critical/IcingaDB: Error during sending query 'XADD' 'icinga:stats' 'MAXLEN' '1' '*' 'ApiListener' '{"perfdata":[{"counter":false,"crit":null,"label":"api_num_co...' ... which has been fired and forgotten: Broken pipe
[2024-12-06 10:24:02 +0100] information/IcingaDB: Connected to Redis server

ref/NC/820479
claimed they start Icinga 2 with Icinga DB enabled – and it OOMs. I hope this spin lock is not responsible, but better safe than sorry.

Also, I'm sure we all agree that spin locks should be avoided, at least where easily possible.

Instead of IoEngine::YieldCurrentCoroutine(yc) until m_Queues.FutureResponseActions.empty(), async-wait a CV which is updated along with m_Queues.FutureResponseActions.
@Al2Klimov Al2Klimov added area/icingadb New backend core/quality Improve code, libraries, algorithms, inline docs labels Dec 6, 2024
@cla-bot cla-bot bot added the cla/signed label Dec 6, 2024
@Al2Klimov Al2Klimov requested a review from yhabteab December 16, 2024 11:33
@@ -340,7 +334,7 @@ void RedisConnection::Connect(asio::yield_context& yc)
}

Handshake(conn, yc);
waitForReadLoop();
m_NoQueuedReads.Wait(yc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often struggle to differentiate between the AsioConditionVariable::Clear() and AsioConditionVariable::Set() methods since they seem to perform very similar functions, and neither of them includes a clear comment explaining their purpose. And yet, I had to trace on my own to understand why the init parameter is set for this in the constructor but not for the others. Could you please provide some comments explaining the scenarios in which this gets unblocked? Additionally, I would suggest naming that new property something like m_ReadLoopDone to better reflect its original intentions.

@@ -577,6 +572,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
}

m_QueuedReads.Set();
m_NoQueuedReads.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not perform this within the ReadLoop method once m_QueuedReads.Wait() returns?

@yhabteab yhabteab added this to the 2.15.0 milestone Jan 13, 2025
@Al2Klimov Al2Klimov removed this from the 2.15.0 milestone Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/icingadb New backend cla/signed core/quality Improve code, libraries, algorithms, inline docs ref/NC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants