@@ -43,7 +43,7 @@ pub(crate) type TransportArc = Arc<RwLock<Option<Arc<dyn Transport>>>>;
43
43
pub struct Client {
44
44
options : ClientOptions ,
45
45
transport : TransportArc ,
46
- session_flusher : SessionFlusher ,
46
+ session_flusher : RwLock < Option < SessionFlusher > > ,
47
47
integrations : Vec < ( TypeId , Arc < dyn Integration > ) > ,
48
48
sdk_info : ClientSdkInfo ,
49
49
}
@@ -60,7 +60,10 @@ impl fmt::Debug for Client {
60
60
impl Clone for Client {
61
61
fn clone ( & self ) -> Client {
62
62
let transport = Arc :: new ( RwLock :: new ( self . transport . read ( ) . unwrap ( ) . clone ( ) ) ) ;
63
- let session_flusher = SessionFlusher :: new ( transport. clone ( ) , self . options . session_mode ) ;
63
+ let session_flusher = RwLock :: new ( Some ( SessionFlusher :: new (
64
+ transport. clone ( ) ,
65
+ self . options . session_mode ,
66
+ ) ) ) ;
64
67
Client {
65
68
options : self . options . clone ( ) ,
66
69
transport,
@@ -128,7 +131,10 @@ impl Client {
128
131
sdk_info. integrations . push ( integration. name ( ) . to_string ( ) ) ;
129
132
}
130
133
131
- let session_flusher = SessionFlusher :: new ( transport. clone ( ) , options. session_mode ) ;
134
+ let session_flusher = RwLock :: new ( Some ( SessionFlusher :: new (
135
+ transport. clone ( ) ,
136
+ options. session_mode ,
137
+ ) ) ) ;
132
138
Client {
133
139
options,
134
140
transport,
@@ -287,12 +293,16 @@ impl Client {
287
293
}
288
294
289
295
pub ( crate ) fn enqueue_session ( & self , session_update : SessionUpdate < ' static > ) {
290
- self . session_flusher . enqueue ( session_update)
296
+ if let Some ( ref flusher) = * self . session_flusher . read ( ) . unwrap ( ) {
297
+ flusher. enqueue ( session_update) ;
298
+ }
291
299
}
292
300
293
301
/// Drains all pending events without shutting down.
294
302
pub fn flush ( & self , timeout : Option < Duration > ) -> bool {
295
- self . session_flusher . flush ( ) ;
303
+ if let Some ( ref flusher) = * self . session_flusher . read ( ) . unwrap ( ) {
304
+ flusher. flush ( ) ;
305
+ }
296
306
if let Some ( ref transport) = * self . transport . read ( ) . unwrap ( ) {
297
307
transport. flush ( timeout. unwrap_or ( self . options . shutdown_timeout ) )
298
308
} else {
@@ -308,7 +318,7 @@ impl Client {
308
318
/// If no timeout is provided the client will wait for as long a
309
319
/// `shutdown_timeout` in the client options.
310
320
pub fn close ( & self , timeout : Option < Duration > ) -> bool {
311
- self . session_flusher . flush ( ) ;
321
+ drop ( self . session_flusher . write ( ) . unwrap ( ) . take ( ) ) ;
312
322
let transport_opt = self . transport . write ( ) . unwrap ( ) . take ( ) ;
313
323
if let Some ( transport) = transport_opt {
314
324
sentry_debug ! ( "client close; request transport to shut down" ) ;
0 commit comments