Skip to content

Conversation

@kpraneet
Copy link

The std_log_impl macro, deadlocks when a write operation fails. This occurs because the stream lock is still held when fallback_on_error attempts to write the error message.

The fix modifies the macro to properly scope the stream lock:

  • Ensure lock is released after write attempts by using explicit scope
  • Handle lock release before error propagation via result?
  • Maintain same behavior for both meta-logging and standard logging paths

Before:

write!(self.stream.lock(), "{}", msg)?;
// Lock held during error propagation

After:

let result = {
    let mut writer = self.stream.lock();
    write!(writer, "{}", msg)
}; // Lock released here
result?; // Error propagation after lock release

This prevents the deadlock by ensuring the stream lock is always released before any error handling occurs through fallback_on_error.

Fixes #150

Validation:

  • Verified fix using the sample test application from the issue
  • Meets contribution guidelines and coding standards
  • All tests pass successfully

The std_log_impl macro, deadlocks when a write operation fails. This occurs because the stream lock is still held when fallback_on_error attempts to write the error message.

The fix modifies the macro to properly scope the stream lock:
- Ensure lock is released after write attempts by using explicit scope
- Handle lock release before error propagation via result?
- Maintain same behavior for both meta-logging and standard logging paths

Before:
write!(self.stream.lock(), "{}", msg)?;
// Lock held during error propagation

After:
let result = {
    let mut writer = self.stream.lock();
    write!(writer, "{}", msg)
}; // Lock released here
result?; // Error propagation after lock release

This prevents the deadlock by ensuring the stream lock is always released before any error handling occurs through fallback_on_error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadlock in fern logging

1 participant