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

Make parking_lot feature fully optional #264

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

Conversation

Cassy343
Copy link

@Cassy343 Cassy343 commented Jun 10, 2022

Currently, if you use the file_appender or rolling_file_appender features then this pulls parking_lot into the dependency tree. This PR would keep parking_lot as a default, but allow users to use those features without parking lot. The implementation details of this are sealed from the public API, so there are no breaking changes.

I am open to suggestions regarding the implementation of this, specifically around handling mutex poisoning.

@estk
Copy link
Owner

estk commented Jun 10, 2022

I'm hesitant to add complexity here, what is the problem with parking_lot?

@Cassy343
Copy link
Author

With some recent improvements that will hopefully land soon in std, using parking lot to eek out a bit of extra performance won't be necessary. Furthermore, parking lot actually backs their implementation with a region of memory on the heap (called the parking lot) to take care of storing metadata. It's not as lightweight as it may seem.

@estk
Copy link
Owner

estk commented Jun 10, 2022

Those seem like great improvements, I'm open to this. One thing that I think can be improved on in this impl is how to handle a poisoned lock. In this context, I think we could probably recover from a poisoned lock.

@Cassy343
Copy link
Author

That was my thought as well, I just was unsure of the implications of always returning the lock after poisoning. For instance it could easily be changed to this:

match self.0.lock() {
    Ok(guard) => guard,
    Err(error) => error.into_inner(),
}

A couple notes on this: are there performance implications for using a poisoned lock as normal? Are we sure that we will always have logically correct behavior regardless of poisoning? I'll think about these issues and post any updates, but I'd like to hear your thoughts too.

@estk
Copy link
Owner

estk commented Jun 13, 2022

@Cassy343
Copy link
Author

The part where it said "Any future attempts to lock the Mutex will return an Err or panic." concerned me due to the panic possibility, but I dug through the code and didn't find anything to that effect.

There are a couple places where we hold a guard across a call to encode from a user-defined encoder. This means that user code could panic and expect to not be called again. I don't really think it matters which side of the fence we come down on here but whatever we do that should be documented.

I'm personally in favor of ignoring poison errors and changing relevant documentation to say "if this method panics, then it still could be called again." If you're fine with that I'll go ahead and render it.

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.

None yet

2 participants