Skip to content

Commit eb2ae56

Browse files
committed
fix(symbolicator): Refresh storage token on task resubmission
The storage token was minted once before entering the retry loop in _process. On TaskIdNotFound or ServiceUnavailable the task is resubmitted with the same token, which may have expired by then. Add a kwargs_cb parameter to _process that is called on every new task submission and merged over the static kwargs. The objectstore callers use this to mint a fresh token each time instead of reusing the original one.
1 parent 57fc590 commit eb2ae56

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/sentry/lang/native/symbolicator.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,21 @@ def __init__(
114114
self.project = project
115115
self.event_id = event_id
116116

117-
def _process(self, task_name: str, path: str, **kwargs):
117+
def _process(
118+
self,
119+
task_name: str,
120+
path: str,
121+
kwargs_cb: Callable[[], dict[str, Any]] | None = None,
122+
**kwargs: Any,
123+
) -> Any:
118124
"""
119125
This function will submit a symbolication task to a Symbolicator and handle
120126
polling it using the `SymbolicatorSession`.
121127
It will also correctly handle `TaskIdNotFound` and `ServiceUnavailable` errors.
128+
129+
`kwargs_cb`, if provided, is called on every new task submission and its result
130+
is merged over `kwargs`. Use this for values that must be fresh on each
131+
(re)submission, such as expiring tokens.
122132
"""
123133
session = SymbolicatorSession(
124134
url=self.base_url,
@@ -137,7 +147,8 @@ def _process(self, task_name: str, path: str, **kwargs):
137147
try:
138148
if not task_id:
139149
# We are submitting a new task to Symbolicator
140-
json_response = session.create_task(path, **kwargs)
150+
create_kwargs = {**kwargs, **(kwargs_cb() if kwargs_cb else {})}
151+
json_response = session.create_task(path, **create_kwargs)
141152
else:
142153
# The task has already been submitted to Symbolicator and we are polling
143154
json_response = session.query_task(task_id)
@@ -190,7 +201,6 @@ def process_minidump(
190201
if minidump.stored_id:
191202
session = get_attachments_session(self.project.organization_id, self.project.id)
192203
storage_url = get_symbolicator_url(session, minidump.stored_id)
193-
storage_token = session.mint_token()
194204
json: dict[str, Any] = {
195205
"platform": platform,
196206
"sources": sources,
@@ -199,11 +209,15 @@ def process_minidump(
199209
"symbolicate": {
200210
"type": "minidump",
201211
"storage_url": storage_url,
202-
"storage_token": storage_token,
203212
"rewrite_first_module": rewrite_first_module,
204213
},
205214
}
206-
res = self._process("process_minidump", "symbolicate-any", json=json)
215+
216+
def cb() -> dict[str, Any]:
217+
json["symbolicate"]["storage_token"] = session.mint_token()
218+
return {"json": json}
219+
220+
res = self._process("process_minidump", "symbolicate-any", kwargs_cb=cb)
207221
return process_response(res)
208222

209223
data = {
@@ -237,7 +251,12 @@ def process_applecrashreport(self, platform: str, report: CachedAttachment):
237251
"storage_token": storage_token,
238252
},
239253
}
240-
res = self._process("process_applecrashreport", "symbolicate-any", json=json)
254+
255+
def cb() -> dict[str, Any]:
256+
json["symbolicate"]["storage_token"] = session.mint_token()
257+
return {"json": json}
258+
259+
res = self._process("process_applecrashreport", "symbolicate-any", kwargs_cb=cb)
241260
return process_response(res)
242261

243262
data = {

0 commit comments

Comments
 (0)