Skip to content

Commit 93d884a

Browse files
jpnurmiclaude
andcommitted
Replace pointer comparison with envelope tag in retry seal check
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8840444 commit 93d884a

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/sentry_envelope.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "sentry_ratelimiter.h"
88
#include "sentry_scope.h"
99
#include "sentry_string.h"
10+
#include "sentry_sync.h"
1011
#include "sentry_transport.h"
1112
#include "sentry_value.h"
1213
#include <assert.h>
@@ -21,7 +22,20 @@ struct sentry_envelope_item_s {
2122
sentry_envelope_item_t *next;
2223
};
2324

25+
static long
26+
next_tag(void)
27+
{
28+
static volatile long counter = 0;
29+
long tag = sentry__atomic_fetch_and_add(&counter, 1);
30+
if (tag == 0) {
31+
// skip 0-sentinel on overflow
32+
tag = sentry__atomic_fetch_and_add(&counter, 1);
33+
}
34+
return tag;
35+
}
36+
2437
struct sentry_envelope_s {
38+
long tag;
2539
bool is_raw;
2640
union {
2741
struct {
@@ -199,6 +213,7 @@ sentry__envelope_new_with_dsn(const sentry_dsn_t *dsn)
199213
return NULL;
200214
}
201215

216+
rv->tag = next_tag();
202217
rv->is_raw = false;
203218
rv->contents.items.first_item = NULL;
204219
rv->contents.items.last_item = NULL;
@@ -236,6 +251,12 @@ sentry__envelope_from_path(const sentry_path_t *path)
236251
return envelope;
237252
}
238253

254+
long
255+
sentry__envelope_get_tag(const sentry_envelope_t *envelope)
256+
{
257+
return envelope->tag;
258+
}
259+
239260
sentry_uuid_t
240261
sentry__envelope_get_event_id(const sentry_envelope_t *envelope)
241262
{

src/sentry_envelope.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ sentry_envelope_t *sentry__envelope_new_with_dsn(const sentry_dsn_t *dsn);
3131
*/
3232
sentry_envelope_t *sentry__envelope_from_path(const sentry_path_t *path);
3333

34+
/**
35+
* Returns a unique non-zero tag assigned at envelope creation.
36+
*/
37+
long sentry__envelope_get_tag(const sentry_envelope_t *envelope);
38+
3439
/**
3540
* This returns the UUID of the event associated with this envelope.
3641
* If there is no event inside this envelope, the empty nil UUID will be

src/sentry_retry.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct sentry_retry_s {
3535
sentry_retry_send_func_t send_cb;
3636
void *send_data;
3737
sentry_mutex_t sealed_lock;
38-
uintptr_t sealed_envelope;
38+
long sealed_tag;
3939
};
4040

4141
sentry_retry_t *
@@ -301,10 +301,10 @@ retry_dump_cb(void *_envelope, void *_retry)
301301
{
302302
sentry_retry_t *retry = (sentry_retry_t *)_retry;
303303
sentry_envelope_t *envelope = (sentry_envelope_t *)_envelope;
304-
if ((uintptr_t)envelope != retry->sealed_envelope) {
304+
if (sentry__envelope_get_tag(envelope) != retry->sealed_tag) {
305305
sentry__run_write_cache(retry->run, envelope, 0);
306306
} else {
307-
retry->sealed_envelope = 0;
307+
retry->sealed_tag = 0;
308308
}
309309
return true;
310310
}
@@ -350,7 +350,7 @@ sentry__retry_enqueue(sentry_retry_t *retry, const sentry_envelope_t *envelope)
350350
sentry__mutex_unlock(&retry->sealed_lock);
351351
return;
352352
}
353-
retry->sealed_envelope = (uintptr_t)envelope;
353+
retry->sealed_tag = sentry__envelope_get_tag(envelope);
354354
sentry__mutex_unlock(&retry->sealed_lock);
355355

356356
sentry__atomic_compare_swap(

0 commit comments

Comments
 (0)