Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ impl Client {
/// If no timeout is provided the client will wait for as long a
/// `shutdown_timeout` in the client options.
pub fn close(&self, timeout: Option<Duration>) -> bool {
if let Some(transport) = self.transport.write().unwrap().take() {
let transport_opt = self.transport.write().unwrap().take();
if let Some(transport) = transport_opt {
sentry_debug!("client close; request transport to shut down");
transport.shutdown(timeout.unwrap_or(self.options.shutdown_timeout))
} else {
Expand Down
2 changes: 1 addition & 1 deletion sentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sentry-log = { version = "0.20.0", path = "../sentry-log", optional = true }
sentry-panic = { version = "0.20.0", path = "../sentry-panic", optional = true }
sentry-slog = { version = "0.20.0", path = "../sentry-slog", optional = true }
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
reqwest_ = { package = "reqwest", version = "0.10.1", optional = true, features = ["blocking", "json"], default-features = false }
reqwest_ = { package = "reqwest", version = "0.10.8", optional = true, features = ["blocking", "json"], default-features = false }
curl_ = { package = "curl", version = "0.4.25", optional = true }
surf_ = { package = "surf", version = "=2.0.0-alpha.4", optional = true }
http-client = { version = "3.0", optional = true }
Expand Down
29 changes: 21 additions & 8 deletions sentry/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ macro_rules! implement_http_transport {
shutdown_signal: Arc<Condvar>,
shutdown_immediately: Arc<AtomicBool>,
queue_size: Arc<Mutex<usize>>,
_handle: Option<JoinHandle<()>>,
handle: Option<JoinHandle<()>>,
}

impl $typename {
Expand All @@ -104,7 +104,7 @@ macro_rules! implement_http_transport {
#[allow(clippy::mutex_atomic)]
let queue_size = Arc::new(Mutex::new(0));
let http_client = http_client(options, $hc_client);
let _handle = Some(spawn(
let handle = Some(spawn(
options,
receiver,
shutdown_signal.clone(),
Expand All @@ -117,7 +117,7 @@ macro_rules! implement_http_transport {
shutdown_signal,
shutdown_immediately,
queue_size,
_handle,
handle,
}
}
}
Expand All @@ -135,14 +135,18 @@ macro_rules! implement_http_transport {

fn shutdown(&self, timeout: Duration) -> bool {
sentry_debug!("shutting down http transport");
let guard = self.queue_size.lock().unwrap();
if *guard == 0 {
if *self.queue_size.lock().unwrap() == 0 {
true
} else {
if let Ok(sender) = self.sender.lock() {
sender.send(None).ok();
}
self.shutdown_signal.wait_timeout(guard, timeout).is_ok()
let guard = self.queue_size.lock().unwrap();
if *guard > 0 {
self.shutdown_signal.wait_timeout(guard, timeout).is_ok()
} else {
true
}
}
}
}
Expand All @@ -152,7 +156,11 @@ macro_rules! implement_http_transport {
sentry_debug!("dropping http transport");
self.shutdown_immediately.store(true, Ordering::SeqCst);
if let Ok(sender) = self.sender.lock() {
sender.send(None).ok();
if sender.send(None).is_ok() {
if let Some(handle) = self.handle.take() {
handle.join().ok();
}
}
}
}
}
Expand Down Expand Up @@ -225,6 +233,7 @@ implement_http_transport! {
let mut body = Vec::new();
envelope.to_writer(&mut body).unwrap();

sentry_debug!("Sending envelope");
match http_client
.post(url.as_str())
.body(body)
Expand All @@ -242,9 +251,13 @@ implement_http_transport! {
disabled = Some(retry_after);
}
}
match resp.text() {
Err(err) => { sentry_debug!("Failed to read sentry response: {}", err); },
Ok(text) => { sentry_debug!("Get response: `{}`", text); },
Comment on lines +255 to +256
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Err(err) => { sentry_debug!("Failed to read sentry response: {}", err); },
Ok(text) => { sentry_debug!("Get response: `{}`", text); },
Err(err) => sentry_debug!("Failed to read sentry response: {}", err),
Ok(text) => sentry_debug!("Get response: `{}`", text),

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering how this does not fail rustfmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its inside the macro, so none of that stuff is rustfmt-ed, also, I needed to wrap this in a block because of the way the sentry_debug macro is built :-(

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks. At least the comment after the } should go usually.

}
}
Err(err) => {
sentry_debug!("Failed to send event: {}", err);
sentry_debug!("Failed to send envelope: {}", err);
}
}

Expand Down