Skip to content

Conversation

@omnibs
Copy link
Member

@omnibs omnibs commented Sep 23, 2025

While digging for space leaks in Nri's Amazonka wrapper, I noticed a bunch of TracingSpan and TracingSpanDetails building up where a Platform.silentHandler was being used.

Digging into it, I noticed silentHandler uses mkHandler, which creates lots of IORefs which, in silentHandler's case, were never useful.

I made an internal nullHandler function specifically for the public silentHandler that does no IO.

I still kept silentHandler : IO LogHandler, even tho I could have made it pure, to keep it a non-breaking change, because I was lazy.

I kept the IO in silentHandler to avoid breaking the public API
Comment on lines +619 to +621
-- | Helper that creates a handler that does nothing. This is intended to power
-- basically @Platform.silentHandler@ and nothing else. We provide this to make
-- @Platform.silentHandler@ as efficient as possible, skipping all side effects.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to mention memory leaks specifically.
Engineers often disagree on the importance of efficiency, whether certain special cases are justified, etc.
But a memory leak is pretty objective. And if someone changes this code, they need to watch out for that.

Copy link
Member Author

@omnibs omnibs Sep 24, 2025

Choose a reason for hiding this comment

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

Ah, I didn't mention memory leaks because I'm not really sure the leaks are caused by mkHandler. We use mkHandler all the time with other LogHandler instances. What's special about silentHandler? Remember we didn't see leakage in high-throughput apps like HQE before #134? Every request in HQE uses mkHandler.

I think it might be more of an issue of how the handler is being used, than the handler itself.

There's this old article by Edsko de Vries on Conduit and space leaks, which I don't really follow, that reinforces the suspicious there's something about our usage that makes this leak. It seems it's not exactly what Edsko describes tho, because -fno-full-laziness didn't help.

This is also why I was more keen on removing the unused silentHandler logger in our Amazonka wrapper, than fixing it to actually log things to the request's tracing span. If I knew what's really causing the leak and how to fix it, I'd rather have logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Although I could leave a word of warning wrt this whole situation. Someone might be grateful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah exactly 👍

@omnibs omnibs added this pull request to the merge queue Sep 24, 2025
Copy link
Contributor

@brian-carroll brian-carroll left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 24, 2025
@omnibs omnibs added this pull request to the merge queue Sep 24, 2025
Merged via the queue into trunk with commit a5803c1 Sep 24, 2025
2 checks passed
@omnibs omnibs deleted the lighter-silent-handler branch September 24, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants