Skip to content

Commit 3a80127

Browse files
authored
appender: remove Sync bound from writer for NonBlocking (#2607)
## Motivation `NonBlocking` from `tracing-appender` wraps a writer and requires that writer to implement `Sync` (among other bounds). However it is not clear why this bound is necessary in first place: this writer is sent to a dedicated thread and never used directly concurrently. #1934 demonstrates that it is a real problem for some people. Also at my current work we hit this issue as well when a third-party writer did not implement `Sync`. Our workaround was to wrap that writer in our own type and manually implement `Send` and `Sync` for it. Needless to say that it is more a hack than a proper solution. ## Solution Remove `Sync` bound in relevant places. Yep, that simple. Probably having it in first place was just an oversight. Closes #1934
1 parent b16965b commit 3a80127

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

tracing-appender/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) mod sync;
188188
/// });
189189
/// # }
190190
/// ```
191-
pub fn non_blocking<T: Write + Send + Sync + 'static>(writer: T) -> (NonBlocking, WorkerGuard) {
191+
pub fn non_blocking<T: Write + Send + 'static>(writer: T) -> (NonBlocking, WorkerGuard) {
192192
NonBlocking::new(writer)
193193
}
194194

tracing-appender/src/non_blocking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ impl NonBlocking {
146146
///
147147
/// [default]: NonBlockingBuilder::default()
148148
/// [builder]: NonBlockingBuilder
149-
pub fn new<T: Write + Send + Sync + 'static>(writer: T) -> (NonBlocking, WorkerGuard) {
149+
pub fn new<T: Write + Send + 'static>(writer: T) -> (NonBlocking, WorkerGuard) {
150150
NonBlockingBuilder::default().finish(writer)
151151
}
152152

153-
fn create<T: Write + Send + Sync + 'static>(
153+
fn create<T: Write + Send + 'static>(
154154
writer: T,
155155
buffered_lines_limit: usize,
156156
is_lossy: bool,
@@ -221,7 +221,7 @@ impl NonBlockingBuilder {
221221
}
222222

223223
/// Completes the builder, returning the configured `NonBlocking`.
224-
pub fn finish<T: Write + Send + Sync + 'static>(self, writer: T) -> (NonBlocking, WorkerGuard) {
224+
pub fn finish<T: Write + Send + 'static>(self, writer: T) -> (NonBlocking, WorkerGuard) {
225225
NonBlocking::create(
226226
writer,
227227
self.buffered_lines_limit,

tracing-appender/src/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt::Debug;
44
use std::io::Write;
55
use std::{io, thread};
66

7-
pub(crate) struct Worker<T: Write + Send + Sync + 'static> {
7+
pub(crate) struct Worker<T: Write + Send + 'static> {
88
writer: T,
99
receiver: Receiver<Msg>,
1010
shutdown: Receiver<()>,
@@ -18,7 +18,7 @@ pub(crate) enum WorkerState {
1818
Shutdown,
1919
}
2020

21-
impl<T: Write + Send + Sync + 'static> Worker<T> {
21+
impl<T: Write + Send + 'static> Worker<T> {
2222
pub(crate) fn new(receiver: Receiver<Msg>, writer: T, shutdown: Receiver<()>) -> Worker<T> {
2323
Self {
2424
writer,

0 commit comments

Comments
 (0)