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

Fix Log::Builder append BroadcastBackend to itself #13405

Merged

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Apr 27, 2023

Resolves #13404

The first commit fixes the immediate bug of adding a broadcast backend to itself.

The second one refactors the builder to avoid mutating a user-provided BroadcastBackend entirely
This is implemented via a flag to indicate whether a Log's backend is user-provided or implicitly created for this log instance.

@straight-shoota straight-shoota marked this pull request as ready for review May 2, 2023 10:18
@bcardiff
Copy link
Member

bcardiff commented May 2, 2023

I'm surprised that the user_provided_broadcast_backend leaves in the Log class instead of being a state tracked inside the Log::Builder directly or in the BroadcastBackend itself. Having a boolean or a @auto_created : Set(BroadcastBackend) in the Log::Builder seems enough without increasing the memory size. Am I missing something?

The private def remove_backend needs to be updated also since it can mutate the broadcast backend also. It is used as part of the spec helper methods for capturing logs IIRC.

@straight-shoota
Copy link
Member Author

Yeah, I wasn't sure where exactly to put that. BroadcastBackend seemed like a bad place because it really shouldn't care about how it's used. Builder would be a natural place because it owns the backend. But it's not as straightforward because its responsibility spans multiple Log instances.
I suppose registering the instances would be another viable option. Lookup costs are a bit higher, but that shouldn't matter much because the builder usually runs sparsely.

@straight-shoota
Copy link
Member Author

straight-shoota commented May 8, 2023

I found a cleaner solution by checking @bindings whether the given broadcast backend was explicitly bound to. If not, it was auto-generated.

remove_backend does not necessarily require any special handling because unbind already verifies that the backend is registered in @bindings. So you cannot accidentally unbind a backend from a user-provided broadcast backend.

@straight-shoota straight-shoota added this to the 1.9.0 milestone May 9, 2023
@straight-shoota straight-shoota merged commit 4c6f27f into crystal-lang:master May 10, 2023
@straight-shoota straight-shoota deleted the fix/log-builder-broadcast branch May 10, 2023 07:45
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log::Builder adds BroadcastBackend to itself
2 participants